Inventory from Ansible
In large setups, it might be beneficial to construct your inventory based on your Ansible inventory. The from-ansible entrypoint of the get command enables the user to create an ANTA inventory from Ansible.
Command overview¶
$ anta get from-ansible --help
Usage: anta get from-ansible [OPTIONS]
Build ANTA inventory from an ansible inventory YAML file.
NOTE: This command does not support inline vaulted variables. Make sure to
comment them out.
Options:
-o, --output FILE Path to save inventory file [env var:
ANTA_INVENTORY; required]
--overwrite Do not prompt when overriding current inventory
[env var: ANTA_GET_FROM_ANSIBLE_OVERWRITE]
-g, --ansible-group TEXT Ansible group to filter
--ansible-inventory FILE Path to your ansible inventory file to read
[required]
--help Show this message and exit.
Warning
-
anta get from-ansibledoes not support inline vaulted variables, comment them out to generate your inventory. -
If the vaulted variable is necessary to build the inventory (e.g.
ansible_host), it needs to be unvaulted forfrom-ansiblecommand to work. -
The current implementation only considers devices directly attached to a specific Ansible group and does not support inheritance when using the
--ansible-groupoption.
The output path is required, either through --output or ANTA_INVENTORY. If the destination file contains data, ANTA asks for confirmation in an interactive terminal. Use --overwrite for intentional, non-interactive replacement.
Example¶
The example uses the following Ansible inventory. Each ansible_host becomes the ANTA host, while the Ansible host key becomes its name:
---
all:
children:
endpoints:
hosts:
srv-pod01:
ansible_host: 192.0.2.11
srv-pod02:
ansible_host: 192.0.2.12
srv-pod03:
ansible_host: 192.0.2.13
Run the conversion against the endpoints group:
anta get from-ansible --ansible-inventory docs/snippets/ansible-inventory.yml --ansible-group endpoints --output anta-inventory.yml --overwrite
The generated anta-inventory.yml contains:
anta_inventory:
hosts:
- host: 192.0.2.11
name: srv-pod01
- host: 192.0.2.12
name: srv-pod02
- host: 192.0.2.13
name: srv-pod03