Basic operations with your inventory
- List managed hosts:
- List defined groups
ansible localhost -m debug -a 'var=groups.keys()'
ansible localhost -m debug -a 'var=groups'
Inventory of managed nodes
Inventory is defined in
/etc/ansible/hosts file. It allows you to define your managed hosts by hostname or IP address, and group them, such as "my_webservers_group" in our example in INI format.
Groups of groups, hierarchies, is also supported using (:children) keyword:
#This is a example of a host configuration file. You can use # to include your comments on hosts file foo_server.example.com 192.168.6.1 bar_server.example.com [my_webservers_group] foo5.example.com bar6.example.com [my_dbservers_group] onedb1.example.com twodb.example.com #Example of a server alias on standard Ansible port my_local_defined_hostname ansible_host=192.0.2.50 #Example of a server alias on a non standard Ansible port my_jumper_server_alias ansible_host=192.0.2.50 ansible_port=5555
You can also read Ansible best practices
- Read about Ansible dynamic inventory https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html
ansible all --list-hosts,
- Ansible: Ansible modules, Playbooks (examples)
ansible-inventory, Ansible Tower, Ansible Galaxy (Roles) (
Ansible Molecule, Ansible collections,
ansible HOSTNAME -m ping,
ansible -m ping,