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.3.0.tar.gz (4.7 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.3.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for ansible_directory_helper-0.3.0.tar.gz
Algorithm Hash digest
SHA256 92239c6ab7eef7981b3767703b9dadadf580e60bb43907c2aabdca241697a6b8
MD5 67083f0e76bc359c4709ddf80e7c9091
BLAKE2b-256 a0b6fe0488b6246dd80e5258a52f06b0278eb7dd9fbde9a934d31cbc17ae4950

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansible_directory_helper-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89e4356147265cd2c9ee3c5c303a34bf6e2ec9db88f9b535d3f0f95d97068340
MD5 58c281c34e84c1bbda2aa96c801014bf
BLAKE2b-256 229efb85665bbf1dc06b557257fc63abf2b653694a7887a12443086f8a011479

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