Using Ansible Callback

Scenario: Set up Ansible callback to monitor running task on remote machine.
Ansible system: CentOS 7, Ansible 2.6
Remote machines:
Both have same root password
1. CentOS 7, ip address: 192.168.99.18
2. CentOS 6, ip address: 192.168.99.19

I set up callback plugins to see running ansible-playbook task on remote machine and it is fun and useful.
To set up callback, edit /etc/ansible/ansible.cfg and change the value to minimal.

# vi /etc/ansible/ansible.cfg

stdout_callback = minimal

Testing
Create playbook to check memory usage free -m on 2 remote machines above.
# vi /etc/ansible/grepmemory.yml

---
- hosts: devservers
 remote_user: tempe
 become: yes
 become_method: su
 gather_facts: False
 tasks:
 - name: Check Memory
 shell: free -m
 delay: 2
 ignore_errors: yes

Run ansible playbook above.
– Output using callback default.

[root@horse ansible]# ansible-playbook --ask-become-pass /etc/ansible/grepmemory.yml
SUDO password:

PLAY [devservers] **************************************************************

TASK [Check Memory] ************************************************************
changed: [192.168.99.19]
changed: [192.168.99.18]

PLAY RECAP *********************************************************************
192.168.99.18 : ok=1 changed=1 unreachable=0 failed=0
192.168.99.19 : ok=1 changed=1 unreachable=0 failed=0

[root@horse ansible]#

– Output using callback minimal.

[root@horse ansible]# ansible-playbook --ask-become-pass /etc/ansible/grepmemory.yml
SUDO password:
192.168.99.19 | SUCCESS | rc=0 >>
 total used free shared buffers cached
Mem: 1860 279 1581 0 11 105
-/+ buffers/cache: 162 1697
Swap: 3999 0 3999

192.168.99.18 | SUCCESS | rc=0 >>
 total used free shared buff/cache available
Mem: 1821 160 1424 9 236 1472
Swap: 2047 0 2047

[root@horse ansible]#

Leave a Reply

Your email address will not be published. Required fields are marked *