# Using Facts, in ansible playbook
[root@ansimaster:~/ansiroot/playbook]# vi playbook1_remote_facts.yml
---
- name: Playbook that will gather facts from webservers.
hosts: webservers
tasks:
- name: Gethering memory details from webservers.
debug:
msg: >
Them memory details of webservers is: {{ ansible_memory_mb }}
is {{ ansible_memory_mb }}
### End of play book "playbook1_remote_facts.yml #####
=========================================
Now lets check and run this playbook
=========================================
[root@ansimaster:~/ansiroot/playbook]# \ playbook 02:54 PM]ansible-playbook playbook1_remote_facts.yml -C
PLAY [Playbook that will gather facts from webservers.] *****************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [192.168.122.50]
TASK [Gethering memory details from webservers.] ************************************************************************************************************************
ok: [192.168.122.50] => {
"msg": "Them memory details of webservers is: {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}} is {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}}\n"
}
PLAY RECAP **************************************************************************************************************************************************************
192.168.122.50 : ok=2 changed=0 unreachable=0 failed=0
[root@ansimaster:~/ansiroot/playbook]# \ playbook 02:54 PM]ansible-playbook playbook1_remote_facts.yml
PLAY [Playbook that will gather facts from webservers.] *****************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [192.168.122.50]
TASK [Gethering memory details from webservers.] ************************************************************************************************************************
ok: [192.168.122.50] => {
"msg": "Them memory details of webservers is: {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}} is {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}}\n"
}
PLAY RECAP **************************************************************************************************************************************************************
192.168.122.50 : ok=2 changed=0 unreachable=0 failed=0
[root@ansimaster:~/ansiroot/playbook]#
[root@ansimaster:~/ansiroot/playbook]# vi playbook1_remote_facts.yml
---
- name: Playbook that will gather facts from webservers.
hosts: webservers
tasks:
- name: Gethering memory details from webservers.
debug:
msg: >
Them memory details of webservers is: {{ ansible_memory_mb }}
is {{ ansible_memory_mb }}
### End of play book "playbook1_remote_facts.yml #####
=========================================
Now lets check and run this playbook
=========================================
[root@ansimaster:~/ansiroot/playbook]# \ playbook 02:54 PM]ansible-playbook playbook1_remote_facts.yml -C
PLAY [Playbook that will gather facts from webservers.] *****************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [192.168.122.50]
TASK [Gethering memory details from webservers.] ************************************************************************************************************************
ok: [192.168.122.50] => {
"msg": "Them memory details of webservers is: {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}} is {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}}\n"
}
PLAY RECAP **************************************************************************************************************************************************************
192.168.122.50 : ok=2 changed=0 unreachable=0 failed=0
[root@ansimaster:~/ansiroot/playbook]# \ playbook 02:54 PM]ansible-playbook playbook1_remote_facts.yml
PLAY [Playbook that will gather facts from webservers.] *****************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [192.168.122.50]
TASK [Gethering memory details from webservers.] ************************************************************************************************************************
ok: [192.168.122.50] => {
"msg": "Them memory details of webservers is: {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}} is {u'real': {u'total': 2775, u'free': 1244, u'used': 1531}, u'swap': {u'cached': 0, u'total': 1023, u'used': 0, u'free': 1023}, u'nocache': {u'used': 607, u'free': 2168}}\n"
}
PLAY RECAP **************************************************************************************************************************************************************
192.168.122.50 : ok=2 changed=0 unreachable=0 failed=0
[root@ansimaster:~/ansiroot/playbook]#
No comments:
Post a Comment