ansible.cfg added the host (file, relative directory)
[defaults]
inventory = hosts
[control] # Include Self (Controller)
ubuntu-c ansible_connection=local
[centos]
centos1 ansible_user=root # Connect using specific user. i.e root
centos2 ansible_user=root ansible_port=2222 # Connect not using default port
centos3 ansible_user=root
[ubuntu]
ubuntu1 ansible_become=true ansible_become_pass=password # Connect as regular user but then "sudo su"
ubuntu2
ubuntu3
ubuntu3 ansible_become=true ansible_become_pass=password
[centos]
centos1 ansible_user=root ansible_port=2222 # Separate if using other port
centos[2:3] ansible_user=root
[ubuntu]
ubuntu[1:3] ansible_become=true ansible_become_pass=password # Use range that repeating.
[centos]
centos1 ansible_port=2222
centos[2:3]
[centos:vars]
ansible_user=root # Pass this line to all CENTOS
[ubuntu]
ubuntu[1:3]
[ubuntu:vars] # Pass this lines to all UBUNTU
ansible_become=true
ansible_become_pass=password
[linux:children] # Subgroup below "ALL"
centos
ubuntu
[all:vars] # Pass to all HOSTS
ansible_port=1234 # Invalid Port... This will override default ports. All will fail except centos1
###OR
[linux:vars] # Pass to all children of linux
ansible_port=1234
YAML Format - Same Purpose
control:
hosts:
ubuntu-c:
ansible_connection: local
centos:
hosts:
centos1:
ansible_port: 2222
centos2:
centos3:
vars:
ansible_user: root
ubuntu:
hosts:
ubuntu1:
ubuntu2:
ubuntu3:
vars:
ansible_become: true
ansible_become_pass: password
linux:
children:
centos:
ubuntu:
JSON Format (UGLY!)
{
"control": {
"hosts": {
"ubuntu-c": {
"ansible_connection": "local"
}
}
},
"centos": {
"hosts": {
"centos1": {
"ansible_port": 2222
},
"centos2": null,
"centos3": null
},
"vars": {
"ansible_user": "root"
}
},
"ubuntu": {
"hosts": {
"ubuntu1": null,
"ubuntu2": null,
"ubuntu3": null
},
"vars": {
"ansible_become": true,
"ansible_become_pass": "password"
}
},
"linux": {
"children": {
"centos": null,
"ubuntu": null
}
}
}