User Guide¶
Exasol Ansible Runner Wrapper wraps Python library ansible_runner and adds the following features:
Enables using Importlib resources as Ansible input directory.
Creates a temporary working directory on the fly.
Creates Ansible inventory.
Enables convenient access to Ansible’s fact cache.
Basic Classes¶
Python package exasol.ansible contains the basic classes as shown in the
following figure.
Initialize the
Contextwith anAccessobject and a tuple of theRepositories.Enter the context to obtain an instance of
Runner.Call method
runner.run()with thePlaybookand a tuple of theHosts.
Additional Details¶
For convenience, class
ImportlibRepositoryextends abstract classRepositoryto enable instantiating a Repository using importlib resources.Class
ContextCopies the resources to a temporary directory for executing Ansible in this directory.
Creates the Ansible inventory file.
Enables passing extra variables to Ansible.
Removes the directory after Ansible has terminated.
Calling
runner.run()with argumentretrieve_facts_from- set to the name of one of the hosts managed by Ansible - will retrieve the Ansible fact cache from this host.You can use class
Factsto conveniently access the facts hierarchically.
Directory Structure¶
For running Ansible, you will usually provide importlib resources as Ansible input directory. That means you will have a directory within your source code containing the playbook, roles, and tasks for Ansible.
Here is an example:
package/
+- name/
+- resources/
+- ansible/
+- playbook.yml
+- roles/
+- tasks/
+- main.yml
The directories and filenames follow the requirements as defined in Ansible input directory.
Example Code¶
from pathlib import Path
import exasol.ansible as ansible
repositories = (ansible.ImportlibRepository("package.name.resources.ansible"),)
playbook = ansible.Playbook("playbook.yml", vars={"key": "value"})
host = ansible.Host("myhost", Path("/tmp/private_key.pem"))
with ansible.Context(ansible.Access(), repositories) as runner:
raw_facts = runner.run(playbook, hosts=(host,) retrieve_facts_from=host.name)
facts = ansible.Facts(raw_facts, prefixes=["pfx"])
value = facts.get("parent", "child")