https://github.com/theasp/ansible-inventory-yaml-groups
Ansible inventory from YML
https://github.com/theasp/ansible-inventory-yaml-groups
ansible ansible-inventory
Last synced: 10 days ago
JSON representation
Ansible inventory from YML
- Host: GitHub
- URL: https://github.com/theasp/ansible-inventory-yaml-groups
- Owner: theasp
- License: mit
- Created: 2017-06-07T18:47:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-10-04T21:18:51.000Z (over 2 years ago)
- Last Synced: 2025-04-03T08:51:25.828Z (about 1 month ago)
- Topics: ansible, ansible-inventory
- Language: Python
- Size: 27.3 KB
- Stars: 6
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ansible-inventory-yaml-groups
Alternative YAML formatted inventory for Ansible. This allows you to to assign groups to hosts as well as hosts to groups, and easily make new groups that are supersets and subsets of other groups.*NOTE:* Ansible supports it's own YAML formatted inventory, see: https://github.com/ansible/ansible/blob/devel/examples/hosts.yaml
# Installation
If you are using Ansible 2.4 or later you can use the inventory plugin version, otherwise you must use the dynamic inventory version.
## Inventory Plugin (2.4+)
Add the following to `ansible.cfg`:
```ini
[defaults]
inventory = hosts.yml
inventory_plugins = /path/to/ansible-inventory-yaml-groups/inventory_plugins[inventory]
enable_plugins = host_list, script, yaml_groups, ini
```## Dynamic Inventory (Any)
In `ansible.cfg`, set `inventory` to `yaml_groups.py`. Addthe following to `ansible.cfg`:
```ini
[defaults]
inventory = /path/to/ansible-inventory-yaml-groups/yaml_groups.py
```You can control the name of the `hosts.yml` file by setting `ANSIBLE_HOSTS_YML`.
# Format of `hosts.yml`
The YAML file is divided into two sections, `groups` and `hosts`.
## Groups (optional)
Entries in `groups` are optional, but they allow the creation groups by listing it's `hosts`, and/or `vars` as in the standard Ansible inventory file. Hosts listed in `hosts` will be created even if there is no corresponding entry in the `hosts` section.You can also provide a list of groups to `include` all hosts from, a list of groups to `require` that each host belong to, and a list of groups to `exclude` that each host must not belong to. The order in which these groups are updated is undefined. You can use the implicit `all` group here, which is only useful for `include`.
## Hosts (optional)
Each host in the `hosts` section can have a list of `groups` that it will be a member of, and host varibles defined in `vars`. Groups will be created even if there is no corresponding group in the groups section.## Example: `hosts.yml`
```yaml
---
groups:
app1-prod:
include:
- app1
require:
- prodapp1-dev:
include:
- app1
require:
- prodapp2-prod:
hosts:
- app2-web1app2:
include:
- app2-prod
- app2-devall-apps:
include:
- app1
- app2hosts:
web-app1-prod.location1.com:
groups:
- app1
- location1
- prod
- webdb-app1-prod.location1.com:
groups:
- app1
- location1
- prod
- dbapp1-dev.location1.com:
vars:
EXAMPLE: "true"
groups:
- app1
- location2
- dev
- web
- db
```# See Also
- https://github.com/ansible/ansible/blob/devel/examples/hosts.yaml
- https://github.com/jtyr/ansible-yaml_inventory