From wikieduonline
Jump to navigation Jump to search

Basic operations with your inventory[edit]

  • List managed hosts:
ansible all --list-hosts
ansible YOUR_GROUP --list-hosts
ansible-inventory --graph
ansible-inventory --list
To filter just one group of host: ansible-inventory --list | jq '.["YOUR_GROUP_NAME"]'
  • List defined groups
ansible localhost -m debug -a 'var=groups.keys()'
ansible localhost -m debug -a 'var=groups'

Inventory of managed nodes[edit] 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: [YOUR_NEW_GROUP_OF_GROUPS:children] [1]

#This is a example of a host configuration file. You can use # to include your comments on hosts file



#Example of a server alias on standard Ansible port
my_local_defined_hostname ansible_host=

#Example of a server alias on a non standard Ansible port

my_jumper_server_alias ansible_host= ansible_port=5555 

You can also read Ansible best practices[2]




See also[edit]