hille721 / ansible-variables Goto Github PK
View Code? Open in Web Editor NEWKeep track of Ansible host context variables
Home Page: https://github.com/hille721/ansible-variables
License: GNU General Public License v3.0
Keep track of Ansible host context variables
Home Page: https://github.com/hille721/ansible-variables
License: GNU General Public License v3.0
No ansible-variables
version in -vvv output:
$ ansible-variables server1 -vvv
ansible-variables [core 2.11.0]
config file = /home/hille/gitrepos/ansible-variables/tests/test_data/ansible.cfg
configured module search path = ['/home/hille/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/hille/gitrepos/ansible-variables/.venv/lib/python3.9/site-packages/ansible
ansible collection location = /home/hille/.ansible/collections:/usr/share/ansible/collections
executable location = /home/hille/gitrepos/ansible-variables/.venv/bin/ansible-variables
python version = 3.9.5 (default, Nov 23 2021, 15:27:38) [GCC 9.3.0]
jinja version = 3.1.2
It should be like in ansible-variables --version
$ ansible-variables --version
ansible-variables 0.5.0 [core 2.11.0]
config file = /home/hille/gitrepos/ansible-variables/tests/test_data/ansible.cfg
configured module search path = ['/home/hille/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/hille/gitrepos/ansible-variables/.venv/lib/python3.9/site-packages/ansible
ansible collection location = /home/hille/.ansible/collections:/usr/share/ansible/collections
executable location = /home/hille/gitrepos/ansible-variables/.venv/bin/ansible-variables
python version = 3.9.5 (default, Nov 23 2021, 15:27:38) [GCC 9.3.0]
jinja version = 3.1.2
libyaml = True
The rich output is nice an human friendly, but there should be also support for yaml and json output. Similar to ansible-inventory
with the flags --yaml
and --json
$ansible-variables server1 --var notdefined -vvv
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'startswith'
the full traceback was:
Traceback (most recent call last):
File "/home/hille/gitrepos/ansible-variables/lib/ansible_variables/cli/__init__.py", line 61, in cli_executor
exit_code = cli.run()
File "/home/hille/gitrepos/ansible-variables/lib/ansible_variables/cli/variables.py", line 130, in run
f"[bold]{variable.name}[/bold]: {variable.value} - [italic]{variable.source_mapped}[/italic]"
File "/home/hille/gitrepos/ansible-variables/lib/ansible_variables/utils/vars.py", line 45, in source_mapped
if self.source.startswith(key):
AttributeError: 'NoneType' object has no attribute 'startswith'
Function run
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
The default rich output should be human readable. But the value of a variable can be nested (list, dictionary) and could be unlimited long. Such values should not be printed in the default output. (They would appear in json or yaml output then see #2)
The current implementation does not support ansible-core < 2.13, as already mentioned by @andreatomassetti in #21 and now also reproduced in the tests (https://github.com/hille721/ansible-variables/actions/runs/5014465851/jobs/8988750817#step:5:66).
Although ansible-core 2.11 is already out of support and 2.12 will be out of support in 4 days (https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix) they are still widely used and as the fix is easy we should support them as well
The current rich output can become a bit hard to read for a lot of variables as no fixed columns are used.
We should at least use a fixed column width for all rows (https://rich.readthedocs.io/en/stable/columns.html#columns)
Further the rich table function could be explored as well (https://rich.readthedocs.io/en/stable/tables.html) (--table
?)
any plans to support dynamic inventory plugins such as aws or digitalocean?
Running ansible-variables -v
or ansible-variables -vvv
will lead to following error if there is an empty file present in the inventory host_vars or group_vars:
ERROR! Unexpected Exception, this is probably a bug: argument of type 'NoneType' is not iterable
the full traceback was:
Traceback (most recent call last):
File "/home/hille/gitrepos/plminfra_ansible/.venv/lib/python3.9/site-packages/ansible/cli/__init__.py", line 647, in cli_executor
exit_code = cli.run()
File "/home/hille/gitrepos/plminfra_ansible/.venv/lib/python3.9/site-packages/ansible_variables/cli/variables.py", line 116, in run
files = variable.file_occurrences(loader=self.loader)
File "/home/hille/gitrepos/plminfra_ansible/.venv/lib/python3.9/site-packages/ansible_variables/utils/vars.py", line 85, in file_occurrences
if self.name in loader.load_from_file(ffile):
TypeError: argument of type 'NoneType' is not iterable
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.