Skip to main content

A small helper library to manage local directories for Ansible Runner

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

About

This is a small helper library to make it easier to supply different variables to the Ansible Runner library, specifically its Input Directory Hierarchy.

I am building this primarily to help me with Lampsible and Docksible, but anyone who is working with Ansible Runner might find this useful.

Installing

Install with Pip: python -m pip install ansible-directory-helper

Usage

If you are using Ansible Runner to develop tools to automate server installations, you likely have many dynamic variables, including but not limited to the system users and host addresses of your remote servers (inventory, in Ansible's parlance), and numerous other variables that your playbooks might expect during runtime. Ansible Runner expects these variables to be present in the so called Input Directory Hierarchy, a predefined directory structure on your local file system. To avoid the hassle of managing these files and directories yourself, you can use this library, which essentially manages this directory structure for you.

Example:

# my_automation_tool.py

from ansible_runner import Runner, RunnerConfig
from ansible_directory_helper.private_data import PrivateData

private_data_dir = './.my-tool/tmp'
project_dir = './my-tool/src/project'

private_data_obj = PrivateData(private_data_dir)

private_data_obj.add_inventory_groups([
    'group1',
    'group2',
])
private_data_obj.add_inventory_host('host1.example.com', 'group1')
private_data_obj.add_inventory_host('host2.example.com', 'group2')
private_data_obj.set_inventory_ansible_user('host1.example.com', 'user1')
private_data_obj.set_inventory_ansible_user('host2.example.com', 'user2')
private_data_obj.write_inventory()

private_data_obj.set_extravar('some_string', 'Hello, World!')
private_data_obj.set_extravar('some_list', ['Hello', 'World'])
private_data_obj.set_extravar('some_dict', {'Hello': 'World'})
private_data_obj.set_extravar('some_none', None)
private_data_obj.write_env()


# Now the files for inventory and extravars are in the exact location and format in which
# Ansible Runner expects them to be, so you can easily
# configure Runner by simply passing the private_data_dir - all the required
# configuration will work.

rc = RunnerConfig(
    private_data_dir=private_data_dir,
    project_dir=project_dir,
    playbook='my-playbook.yml'
)

rc.prepare()
r = Runner(config=rc)
r.run()

# Do this to delete the private_data_dir from your filesystem.
# This is important because it contains sensitive data.
private_data_obj.cleanup_dir()

Running unit tests

python -m unittest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansible_directory_helper-0.2.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ansible_directory_helper-0.2.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ansible_directory_helper-0.2.1.tar.gz.

File metadata

File hashes

Hashes for ansible_directory_helper-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1bee5413200c7c702f5b1e9c60fbe3dfc91275b364709f9cf372ce5422556d7d
MD5 3af5c02f52b7409cc62f014af9c7ce87
BLAKE2b-256 8cef0cf543062012c9b0278cab109ad1e62c6a10cfbe8bb98867c9ddfd0938a5

See more details on using hashes here.

File details

Details for the file ansible_directory_helper-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_directory_helper-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71adc424a7b31f01fea7d116e2367047877e323f1689e180523de7526b8264fc
MD5 60f284d02a9abcd8d6134a88d1f194c0
BLAKE2b-256 0caf989ca09e7b3a5e02f692f63fec585d86dbd59dcb50b7cee39f4716e9f99e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page