-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This enables easy access to Ansible configuration.
- Loading branch information
Showing
7 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
# ansible-compat | ||
A python package containing functions that help interacting with various versions of Ansible | ||
|
||
A python package contains functions that facilitates working with various | ||
versions of Ansible, 2.9 and newer. | ||
|
||
## Access to Ansible configuration | ||
|
||
As you may not want to parse `ansible-config dump` yourself, you | ||
can make use of a simple python class that facilitates access to | ||
it, using python data types. | ||
|
||
```python | ||
from ansible_compat.config import AnsibleConfig | ||
|
||
|
||
def test_example_config(): | ||
cfg = AnsibleConfig() | ||
assert isinstance(cfg.ACTION_WARNINGS, bool) | ||
# you can also use lowercase: | ||
assert isinstance(cfg.action_warnings, bool) | ||
# you can also use it as dictionary | ||
assert cfg['action_warnings'] == cfg.action_warnings | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,8 @@ test = | |
flaky | ||
pytest | ||
pytest-cov | ||
pytest-markdown | ||
pytest-plus | ||
|
||
[options.packages.find] | ||
where = src | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Tests for ansible_compat.config submodule.""" | ||
import pytest | ||
|
||
import ansible_compat | ||
|
||
|
||
def test_config() -> None: | ||
"""Checks that config vars are loaded with their expected type.""" | ||
config = ansible_compat.config.AnsibleConfig() | ||
assert isinstance(config.ACTION_WARNINGS, bool) | ||
assert isinstance(config.CACHE_PLUGIN_PREFIX, str) | ||
assert isinstance(config.CONNECTION_FACTS_MODULES, dict) | ||
assert config.ANSIBLE_COW_PATH is None | ||
assert isinstance(config.NETWORK_GROUP_MODULES, list) | ||
assert isinstance(config.DEFAULT_GATHER_TIMEOUT, int) | ||
|
||
# check lowercase and older name aliasing | ||
assert isinstance(config.collections_paths, list) | ||
assert isinstance(config.collections_path, list) | ||
|
||
with pytest.raises(AttributeError): | ||
print(config.THIS_DOES_NOT_EXIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters