{"id":22388146,"url":"https://github.com/sermilrod/ansible-dynamic-inventory","last_synced_at":"2026-03-16T07:06:53.897Z","repository":{"id":241221674,"uuid":"101052375","full_name":"sermilrod/ansible-dynamic-inventory","owner":"sermilrod","description":"Ansible dynamic inventory interface from an static hosts file","archived":false,"fork":false,"pushed_at":"2017-08-22T13:33:35.000Z","size":1,"stargazers_count":4,"open_issues_count":0,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-11T01:35:37.895Z","etag":null,"topics":["ansible","ansible-inventory","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sermilrod.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-08-22T10:42:45.000Z","updated_at":"2025-08-20T10:55:15.000Z","dependencies_parsed_at":"2024-05-23T04:35:12.454Z","dependency_job_id":null,"html_url":"https://github.com/sermilrod/ansible-dynamic-inventory","commit_stats":null,"previous_names":["sermilrod/ansible-dynamic-inventory"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sermilrod/ansible-dynamic-inventory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sermilrod%2Fansible-dynamic-inventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sermilrod%2Fansible-dynamic-inventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sermilrod%2Fansible-dynamic-inventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sermilrod%2Fansible-dynamic-inventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sermilrod","download_url":"https://codeload.github.com/sermilrod/ansible-dynamic-inventory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sermilrod%2Fansible-dynamic-inventory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30571233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-16T06:02:37.763Z","status":"ssl_error","status_checked_at":"2026-03-16T06:02:14.913Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","python"],"created_at":"2024-12-05T02:12:30.766Z","updated_at":"2026-03-16T07:06:53.861Z","avatar_url":"https://github.com/sermilrod.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ansible-dynamic-inventory\nDo you have Bare Metal or virtualized platform without a good API? If so, would you like to use a dynamic inventory like it was AWS, Azure or OpenStack?\n\nThis project provides a dynamic inventory interface that allows you to simplify your static management of the hosts file and also manage your legacy platform inventory like it was a cloud provider.\n\n## Setup\n\n1. Copy src/inventory.py file into your inventory folder in Ansible\n2. Copy the src/hosts.yml sample into your inventory folder, at the same level of the inventory.py, and customize it to your needs.\n3. [Configure Ansible to use the inventory.py](http://docs.ansible.com/ansible/latest/intro_inventory.html#splitting-out-host-and-group-specific-data) (an example through ansible.cfg):\n    ```\n    [defaults]\n    hostfile = ./inventory/inventory.py\n    ```\n## Usage\n\nTo verify that it works:\n\n```bash\n$ chmod u+x inventory.py\n$ python inventory.py --list\n```\n\nTo take advance of this inventory script you will need to generate your hosts.yml according to some patterns.\nFirst of all, you don't want to generate all the possible groups of your machines manually. For that we use tags:\n```\nnode-1:\n  ansible_ssh_host: node-1.example.com\n  tags:\n    - development\n    - node\nnode-2:\n  ansible_ssh_host: node-2.example.com\n  tags:\n    - production\n    - node\n```\nGiven that list of hosts the inventory script will generate all the possible groups based on the tags:\n```\n{\n  'development': ['node-1.example.com'],\n  'production': ['node-2.example.com'],\n  'node': ['node-1.example.com', 'node-2.example.com']\n}\n```\nThat will allow you to run your playbook by using intersections without taking the effort of thinking of all possible combinations of tags:\n```bash\n$ ansible-playbook --limit 'node:\u0026development' myplaybook.yml\n$ ansible-playbook --limit 'node:\u0026production' myplaybook.yml\n$ ansible-playbook --limit 'node' myplaybook.yml\n```\nOr alternatively within your play (as an example):\n```\n---\n- name: foo\n  hosts: \"node:\u0026{{ env }}\"\n\n  roles:\n    - role: foo-role\n```\n```bash\n$ ansible-playbook -e 'env=production' myplaybook.yml\n```\n\nIf you want to include host variables you have to add a key to the host properties:\n```\nnode-1:\n  ansible_ssh_host: node-1.example.com\n  tags:\n    - development\n    - node\n  hostvars:\n    attr_1: value1\n    attr_2:\n      - value2\n      - value3\n    attr_3:\n      something: value4\n```\n\nUltimately, as you still don't have an API that can provide you with an organized result like this, you will have to maintain a simple list of tagged nodes, which is better than an unorganized and full of duplication plain hosts file. All the possible combinations are handled by the inventory script and returned to Ansible.\n\n### Developer considerations:\nThe dynamic inventory script comes with a tests that can be run:\n```bash\n$ cd src/\n$ python -m unittest inventory_test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsermilrod%2Fansible-dynamic-inventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsermilrod%2Fansible-dynamic-inventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsermilrod%2Fansible-dynamic-inventory/lists"}