{"id":15049996,"url":"https://github.com/hille721/ansible-variables","last_synced_at":"2025-04-10T02:13:51.278Z","repository":{"id":152932589,"uuid":"627605319","full_name":"hille721/ansible-variables","owner":"hille721","description":"Keep track of Ansible host context variables","archived":false,"fork":false,"pushed_at":"2025-04-07T20:31:48.000Z","size":551,"stargazers_count":23,"open_issues_count":7,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T02:13:37.916Z","etag":null,"topics":["ansible","ansible-inventory","ansible-variables"],"latest_commit_sha":null,"homepage":"https://github.com/hille721/ansible-variables","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hille721.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-13T20:16:31.000Z","updated_at":"2025-03-24T13:59:53.000Z","dependencies_parsed_at":"2024-05-06T23:22:15.065Z","dependency_job_id":"ec2e97a5-53a9-4a64-9aab-19505fe71ea4","html_url":"https://github.com/hille721/ansible-variables","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hille721%2Fansible-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hille721%2Fansible-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hille721%2Fansible-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hille721%2Fansible-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hille721","download_url":"https://codeload.github.com/hille721/ansible-variables/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142902,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-inventory","ansible-variables"],"created_at":"2024-09-24T21:24:10.691Z","updated_at":"2025-04-10T02:13:51.260Z","avatar_url":"https://github.com/hille721.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ansible-variables\n\n[![PyPI version][pypi-version-badge]][pypi-link]\n[![PyPI platforms][pypi-platforms-badge]][pypi-link]\n[![pre-commit][pre-commit-badge]][pre-commit-link]\n[![Ruff][ruff-badge]][ruff-link]\n\nThe Ansible inventory provides a very powerful framework to declare variables in a hierarchical manner.\nThere a lof of different places where a variable can be defined (inventory, host_vars, groups_vars, ...)\nand Ansible will merge them in a specific order\n([variable precedence](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#understanding-variable-precedence)).\n\n`ansible-variables` will help to keep track of your host context variables:\n\n- inventory file or script group vars\n- inventory group_vars/all\n- inventory group_vars/\\*\n- inventory file or script host vars\n- inventory host_vars/\\*\n\nBased on one host it will return a list with all variables, values and variable type.\n\nTested with `ansible-core` 2.11 - 2.18.\n\n## Installation\n\n```bash\npip install ansible-variables\n```\n\n## Usage\n\nThe command line usage is similar to the official Ansible CLI tools, especially like ansible-inventory,\nthus to see all possible commands and options run\n\n```plain\nansible-variables --help\n```\n\n### Get all variables for a host\n\nThe basic usage is pretty simple, you only need to pass the Ansible hostname to it:\n\n```plain\nansible-variables mywebserver\n```\n\nThis results in following simple rich formatted output\n![command_simple](https://github.com/hille721/ansible-variables/raw/main/docs/img/command_simple.png)\n\nThe verbosity can be increased Ansible like with `-v`, `-vvv`, ...\n\nWith `-v` the inventory files where the variable is defined, will be printed. The last file wins.\n\n![command_simple_verbose](https://github.com/hille721/ansible-variables/raw/main/docs/img/command_simple_verbose.png)\n\nWith `-vvv` it will also print all files which were considered to look for the variable.\n\n### Get one specific variables for a host\n\nIf you are only interested in one variable you can specify it with `--var`:\n\n```plain\nansible-variables mywebserver --var foo\n```\n\nSame es above, the verbosity can also increase here.\n\n### More customization\n\nWith `--help` you will see which further arguments are possible, e.g. you can set the path to your inventory with `-i`\n\n```plain\nansible-variables mywebserver -i /path/to/inventory\n```\n\n## Implementation\n\nThis tool is tightly coupled to the Ansible library (`ansible-core`) and simple reuses what is already there.\nThe whole structure and implementation was inspired and oriented by the implementation of\n[`ansible-inventory`](https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/inventory.py).\n\nTo get the source and the inventory files in which Ansible will look for a variable,\nwe are using a [debug flag](https://github.com/ansible/ansible/blob/devel/lib/ansible/vars/manager.py#L187)\nin Ansible's `get_vars` method.\n\nAs as result, the output of `ansible-variables` can be fully trusted\nas it uses the same methods as Ansible to get the variable precedence.\n\n## Limitations\n\n- as written in the description, this tool only shows host context variables and\n  does not know anything about playbook or role variables or command line options.\n\n## Credits\n\n- the screenshots used in this README where created with [termshot](https://github.com/homeport/termshot)\n\n## License\n\nThis project is licensed under the [GNU General Public License v3.0](https://github.com/hille721/ansible-variables/blob/main/LICENSE)\n\n[pre-commit-badge]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white%3E\n[pre-commit-link]: https://pre-commit.com/\n[pypi-link]: https://pypi.org/project/ansible-variables/\n[pypi-platforms-badge]: https://img.shields.io/pypi/pyversions/ansible-variables\n[pypi-version-badge]: https://badge.fury.io/py/ansible-variables.svg\n[ruff-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\n[ruff-link]: https://github.com/astral-sh/ruff\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhille721%2Fansible-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhille721%2Fansible-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhille721%2Fansible-variables/lists"}