8000 GitHub - ansible/ansible-compat at v0.2.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ansible/ansible-compat

Repository files navigation

ansible-compat

A python package contains functions that facilitate working with various versions of Ansible 2.9 and newer.

Using Ansible runtime

from ansible_compat.runtime import Runtime

def test_runtime():

    # instantiate the runtime using isolated mode, so installing new
    # roles/collections do not pollute the default setup.
    runtime = Runtime(isolated=True)

    # Print Ansible core version
    print(runtime.version)  # 2.9.10 (Version object)
    # Get configuration info from runtime
    print(runtime.config.collections_path)

    # Install a new collection
    runtime.install_collection("containers.podman")

    # Execute a command
    result = runtime.exec(["ansible-doc", "--list"])

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.

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

About

A python package containing functions that help interacting with various versions of Ansible

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 23

0