Keep track of Ansible host context variables
Project description
ansible-variables
The Ansible inventory provides a very powerful framework to declare variables in a hierarchical manner. There a lof of differnt places where a variable can be definied (inventory, host_vars, groups_vars, ...) and Ansible will merge them in a specific order (variable precedence).
ansible-variables
will help to keep track of your host context variables:
- inventory file or script group vars
- inventory group_vars/all
- inventory group_vars/*
- inventory file or script host vars
- inventory host_vars/*
Based on one host it will retun a list with all variables, values and variable type.
Installation
pip install ansible-variables
Usage
The command line usage is simmilar to the official Ansible CLI tools, especially like ansible-inventory, thus to see all possible commands and options run
ansible-variables --help
Get all variables for a host
The basic usage is pretty simple, you only need to pass the Ansible hostname to it:
ansible-variables mywebserver
This results in following simple rich formatted output
The vervosity can be increased Ansible like with -v
, -vvv
, ...
With -v
the inventory files where the variable is defined, will be printed. The last file wins.
With -vvv
it will also print all files which were considered to look for the variable.
Get one specific variables for a host
If you are only interested in one variable you can specify it with --var
:
ansible-variables mywebserver --var foo
Same es above, the verbosity can also increase here.
More customization
With --help
you will see which furhter arguments are possible, e.g. you can set the path to your inventory with -i
ansible-variables mywebserver -i /path/to/inventory
Implementation
This tool is tightly coupled to the Ansible library (ansible-core
) and simple reuses what is already there.
The whole structure and implemntation was inspired and oriented by the implementation of ansible-inventory
.
To get the source and the inventory files in which Ansible will look for a variable, we are using a debug flag in Ansible's get_vars
method.
As as result, the output of ansible-variables
can be fully trusted as it uses the same methods as Ansible to get the variable precedence.
Limitations
- as written in the description, this tool shows only host context varialbe and there does not know anything about playbook or role variables or command line options.
Credits
I would like to thank the termshot project for their excellent tool that allowed me to easily create the screenshots used in this README.md file.
If you're interested in learning more about the termshot project, you can visit their website at https://termshot.app/ or check out their GitHub repository at https://github.com/nickolasburr/termshot.
License
This project is licensed under the GNU General Public License v3.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ansible_variables-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a6ba74ab4e1ff29cff8133838e73e672f824c419e8ba88b5280b2006decea72 |
|
MD5 | e4a8e4b52cff14db993abf343fdced41 |
|
BLAKE2b-256 | 0c5e0c90364aa870e7d42807833980b3bd495c93d598a713b513c34650d84073 |