inventory Features:-
1)Behavioral Parameters
2)Groups
3)Group of Groups
4)Assign Variables
5)Scaling Out using multiple files
6)Static/Dynamic
examples:-
cat /etc/ansible/ansible.cfg|grep -i inventory
[ansible@ansibleserver ~]$ cat /etc/ansible/ansible.cfg |grep -i inventory
inventory = /etc/ansible/hosts
#cat /etc/ansible/hosts
10.25.12.11
10.25.12.10
10.25.12.13
[db]
10.25.12.10
[web]
10.25.12.13
[datacenter:children]
db
web
To know List of Ansible hosts:-
[ansible@ansibleserver ~]$ ansible all --list-hosts
hosts (3):
10.25.12.10
10.25.12.11
10.25.12.13
[ansible@ansibleserver ~]$ ansible db --list-hosts
hosts (1):
10.25.12.10
[ansible@ansibleserver ~]$ ansible web --list-hosts
hosts (1):
10.25.12.13
[ansible@ansibleserver ~]$ ansible datacenter --list-hosts
hosts (2):
10.25.12.10
10.25.12.13
=================
we can create local inventories as well.
ex:-
[ansible@ansibleserver ~]$ cat inventory
10.25.12.13 ansible_ssh_user=ansible ansible_ssh_pass=ansible
[ansible@ansibleserver ~]$ ansible all -i inventory -m ping
10.25.12.13 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[ansible@ansibleserver ~]$ ansible all -i inventory -a 'df -h'
10.25.12.13 | CHANGED | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 481M 0 481M 0% /dev
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 490M 6.9M 484M 2% /run
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
[ansible@ansibleserver ~]$ ansible all -i inventory -a 'hostname'
10.25.12.13 | CHANGED | rc=0 >>
clinet.example.com
==============
[ansible@ansibleserver ~]$ cat inventory
10.25.12.13 ansible_ssh_user=ansible ansible_ssh_pass=ansible
10.25.12.11 ansible_ssh_user=ansible ansible_ssh_pass=ansible ansible_python_interpreter=/usr/bin/python
[ansible@ansibleserver ~]$ ansible all -i inventory -a 'hostname'
10.25.12.11 | CHANGED | rc=0 >>
yumserver.example.com
10.25.12.13 | CHANGED | rc=0 >>
clinet.example.com
==============
Declaring inventory Varibles:-
[ansible@ansibleserver ~]$ cat inventory
10.25.12.13 ansible_ssh_user=ansible ansible_ssh_pass=ansible
10.25.12.11 ansible_ssh_user=ansible ansible_ssh_pass=ansible ansible_python_interpreter=/usr/bin/python
[db]
10.25.12.11
[web]
10.25.12.13
[datacenter:children]
db
web
[datacenter:vars]
ansible_ssh_user=student
ansible_ssh_pass=student
[ansible@ansibleserver ~]$
[ansible@ansibleserver ~]$ ansible datacenter -i inventory -m ping
10.25.12.11 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.25.12.13 | SUCCESS => {
"changed": false,
"ping": "pong"
}
1)Behavioral Parameters
2)Groups
3)Group of Groups
4)Assign Variables
5)Scaling Out using multiple files
6)Static/Dynamic
examples:-
cat /etc/ansible/ansible.cfg|grep -i inventory
[ansible@ansibleserver ~]$ cat /etc/ansible/ansible.cfg |grep -i inventory
inventory = /etc/ansible/hosts
#cat /etc/ansible/hosts
10.25.12.11
10.25.12.10
10.25.12.13
[db]
10.25.12.10
[web]
10.25.12.13
[datacenter:children]
db
web
To know List of Ansible hosts:-
[ansible@ansibleserver ~]$ ansible all --list-hosts
hosts (3):
10.25.12.10
10.25.12.11
10.25.12.13
[ansible@ansibleserver ~]$ ansible db --list-hosts
hosts (1):
10.25.12.10
[ansible@ansibleserver ~]$ ansible web --list-hosts
hosts (1):
10.25.12.13
[ansible@ansibleserver ~]$ ansible datacenter --list-hosts
hosts (2):
10.25.12.10
10.25.12.13
=================
we can create local inventories as well.
ex:-
[ansible@ansibleserver ~]$ cat inventory
10.25.12.13 ansible_ssh_user=ansible ansible_ssh_pass=ansible
[ansible@ansibleserver ~]$ ansible all -i inventory -m ping
10.25.12.13 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[ansible@ansibleserver ~]$ ansible all -i inventory -a 'df -h'
10.25.12.13 | CHANGED | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 481M 0 481M 0% /dev
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 490M 6.9M 484M 2% /run
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
[ansible@ansibleserver ~]$ ansible all -i inventory -a 'hostname'
10.25.12.13 | CHANGED | rc=0 >>
clinet.example.com
==============
[ansible@ansibleserver ~]$ cat inventory
10.25.12.13 ansible_ssh_user=ansible ansible_ssh_pass=ansible
10.25.12.11 ansible_ssh_user=ansible ansible_ssh_pass=ansible ansible_python_interpreter=/usr/bin/python
[ansible@ansibleserver ~]$ ansible all -i inventory -a 'hostname'
10.25.12.11 | CHANGED | rc=0 >>
yumserver.example.com
10.25.12.13 | CHANGED | rc=0 >>
clinet.example.com
==============
Declaring inventory Varibles:-
[ansible@ansibleserver ~]$ cat inventory
10.25.12.13 ansible_ssh_user=ansible ansible_ssh_pass=ansible
10.25.12.11 ansible_ssh_user=ansible ansible_ssh_pass=ansible ansible_python_interpreter=/usr/bin/python
[db]
10.25.12.11
[web]
10.25.12.13
[datacenter:children]
db
web
[datacenter:vars]
ansible_ssh_user=student
ansible_ssh_pass=student
[ansible@ansibleserver ~]$
[ansible@ansibleserver ~]$ ansible datacenter -i inventory -m ping
10.25.12.11 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.25.12.13 | SUCCESS => {
"changed": false,
"ping": "pong"
}
No comments:
Post a Comment