{"id":14128649,"url":"https://github.com/iautom8things/ansible-meta-dynamic-inventory","last_synced_at":"2025-08-03T23:31:56.647Z","repository":{"id":141766269,"uuid":"67791594","full_name":"iautom8things/ansible-meta-dynamic-inventory","owner":"iautom8things","description":"Naming is hard.  This wrapper script allows you to use set notation with dynamic host groups.","archived":true,"fork":false,"pushed_at":"2017-07-23T01:32:12.000Z","size":10,"stargazers_count":23,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-01T06:14:55.627Z","etag":null,"topics":["ansible","ansible-inventory","aws","devops","devops-tools","dynamic-inventory"],"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/iautom8things.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}},"created_at":"2016-09-09T10:53:26.000Z","updated_at":"2023-02-28T20:35:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"a7f0944c-7819-4966-a42d-4bed04b2e25a","html_url":"https://github.com/iautom8things/ansible-meta-dynamic-inventory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iautom8things%2Fansible-meta-dynamic-inventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iautom8things%2Fansible-meta-dynamic-inventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iautom8things%2Fansible-meta-dynamic-inventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iautom8things%2Fansible-meta-dynamic-inventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iautom8things","download_url":"https://codeload.github.com/iautom8things/ansible-meta-dynamic-inventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228571844,"owners_count":17938772,"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","aws","devops","devops-tools","dynamic-inventory"],"created_at":"2024-08-15T16:01:59.782Z","updated_at":"2024-12-07T06:31:34.002Z","avatar_url":"https://github.com/iautom8things.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# ansible-meta-dynamic-inventory\n\nThis script takes, as input, the output of a dynamic inventory script and reads in another file, called a Groupsfile, that allows the creation of new groups using any of Ansible's Pattern set notations, and then outputs an updated version of the dynamic inventory that it received.\n\n## Who does this help?\nAnyone that extensively uses Ansible Patterns.\n\n## What does this give you?\n\n1. The ability to effectively alias your patterns, by creating new groups from your patterns.\n2. The ability to define _group_vars_ for your patterned groups.\n3. A single source for defining your patterned groups.\n4. More reusable playbooks.\n\n## Dependancies\n\n- Python (developed against 2.7.12)\n- Parsley v1.3 [[link]](https://pypi.python.org/pypi/Parsley)\n\n## Introduction\n\nAnsible has a concept of _Inventory_, this is your listing/groupings of all of the machines in your infrastructure. Ansible allows for two types of inventories: _static_ and _dynamic_.\n\nHere is an example of a simple static inventory:\n\n```\n[web]\n10.0.1.2\n10.0.1.3\n\n[db]\n10.2.0.2\n10.2.0.3\n\n[aws_us_east]\n\n[aws_us_east:children]\nweb\ndb\n```\n\nThis static inventory file describes two groups (`web`,`db`) with two hosts each, and a third group (`aws_us_east`) that is the union of web and db.  Static inventory works great if you have very few machines that never change, and it becomes virtually useless with the more hosts you have or the more _dynamic_ your inventory is.\n\n### Dynamic inventory to the rescue!\n\nDynamic inventory is an executable script that inspects your infrastructure and dynamically creates groups out of them. If you're on AWS and using Ansible, then you're likely familiar with `ec2.py` [[link]](https://raw.githubusercontent.com/ansible/ansible/stable-1.9/plugins/inventory/ec2.py), a Python script that uses your AWS credentials to inspect EC2 and dynamically create groups based on VPCs, security groups, tags and much more.\n\n### Ansible Patterns\n\nAnsible also has this great feature that allows you to use set functions like union, intersection and difference on your host groups, called Patterns [[link]](http://docs.ansible.com/ansible/intro_patterns.html).  This allows for you to home in on _just the right_ group of hosts to operate on.\n\n#### Examples:\n- Union *(All API and WEB nodes)*\n\n\t\ttag_Product_api:tag_Product_web\n\n- Intersection *(Production API nodes)*\n\n\t\ttag_Product_api:\u0026tag_Env_prod\n\n- Difference *(Non-API nodes)*\n\n\t\ttag_Product_api:!tag_Env_prod\n\n- Slicing *(The first two nodes with tag Product=api)*\n\n\t\ttag_Product_api[0:2]\n\n*See the Ansible documentation for a complete list of possible patterns.*\n\n### The Rub\n\nAnsible Patterns are limited to being used on the command line:\n\n```\n$ ansible tag_Env_prod:\u0026tag_Service_web -m service -a \"name=httpd state=restarted\"\n```\n\nOr they can be used as the host specifier for a play:\n\n```\n---\n- name: Install SomeService Role\n  hosts: tag_Env_stg:!tag_Service_elk\n  become: yes\n\n  roles:\n    - SomeService\n```\n\nThis means that you _cannot_ use patterns in a static inventory file.  So the following **does not work**:\n\n```\n[web]\n5.5.5.5\n10.10.10.10\n\n[prod]\n10.10.10.10\n\n[web_prod]\n\n[web_prod:children]\nweb:\u0026prod\n```\nThis static inventory file attempts to create a `web_prod` group that only consists of machines in _both_ `web` \u0026\u0026 `prod`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiautom8things%2Fansible-meta-dynamic-inventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiautom8things%2Fansible-meta-dynamic-inventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiautom8things%2Fansible-meta-dynamic-inventory/lists"}