GithubHelp home page GithubHelp logo

hille721 / ansible-variables Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 1.0 455 KB

Keep track of Ansible host context variables

Home Page: https://github.com/hille721/ansible-variables

License: GNU General Public License v3.0

Python 100.00%
ansible ansible-inventory ansible-variables

ansible-variables's People

Contributors

andreatomassetti avatar dependabot[bot] avatar github-actions[bot] avatar hille721 avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ansible-variables's Issues

output with -vvv does not show ansible-variables version as --version does

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

Support --yaml and --json output

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

passing undefined variable to --var will lead to Exception

$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'

Do not print lists and dictionaries in rich output

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)

Not working with ansible-core 2.11 and ansible-core 2.12

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

ERROR! Unexpected Exception, this is probably a bug: argument of type 'NoneType' is not iterable

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.