handlers & register in ansible

[root@workstation ~]# vim register.yaml

– name: checking the register module functionality
hosts: localhost
tasks:
– name:
command: ps
register: output
– debug: msg=”{{ output.stdout }}”
====================================================
[root@workstation ~]# ansible-playbook –syntax-check register.yaml

playbook: register.yaml

[root@workstation ~]# ansible-playbook register.yaml

PLAY [checking the register module functionality] ******************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
“msg”: ” PID TTY TIME CMD\n 9690 pts/0 00:00:00 bash\n 11851 pts/0 00:00:00 ansible-playboo\n 11894 pts/0 00:00:00 ansible-playboo\n 11904 pts/0 00:00:00 sh\n 11905 pts/0 00:00:00 python2\n 11906 pts/0 00:00:00 python2\n 11907 pts/0 00:00:00 ps”
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
====================================================
[root@workstation ~]# vim register.yaml

– name: checking the register module functionality
hosts: localhost
tasks:
– name:
shell: “ps -aux | grep ansible”
register: output
– debug: msg={{ output.stdout }}
[root@workstation ~]# ansible-playbook register.yaml

PLAY [checking the register module functionality] ******************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [command] *****************************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
“msg”: “root 12337 42.0 5.4 338628 26212 pts/0 Rl+ 03:02 0:00 /usr/bin/python2 /usr/bin/ansible-playbook register.yaml\nroot 12380 0.0 5.9 345696 28664 pts/0 S+ 03:02 0:00 /usr/bin/python2 /usr/bin/ansible-playbook register.yaml\nroot 12390 0.0 0.2 113116 1204 pts/0 S+ 03:02 0:00 /bin/sh -c /usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1485725579.35-37718783810169/command.py; rm -rf \”/root/.ansible/tmp/ansible-tmp-1485725579.35-37718783810169/\” > /dev/null 2>&1 && sleep 0\nroot 12391 0.0 1.6 189176 7976 pts/0 S+ 03:02 0:00 /usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1485725579.35-37718783810169/command.py\nroot 12392 0.0 2.6 206164 12668 pts/0 S+ 03:02 0:00 /usr/bin/python2 /tmp/ansible_70E9iy/ansible_module_command.py\nroot 12393 0.0 0.2 113116 1200 pts/0 S+ 03:02 0:00 /bin/sh -c ps -aux | grep ansible\nroot 12395 0.0 0.1 112644 932 pts/0 S+ 03:02 0:00 grep ansible”
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
====================================================

[root@workstation ~]# vim handler.yaml

– name: checking handler functioning
hosts: localhost
tasks:
– name: starting apache service by adding html content
copy:
src: /root/index.html
dest: /var/www/html/index.html
notify:
– start_apache
handlers:
– name: start_apache
service:
name: httpd
state: started
[root@workstation ~]# vim /root/index.html
this for checking handler

[root@workstation ~]# ansible-playbook –syntax-check handler.yaml

playbook: handler.yaml

[root@workstation ~]# ansible-playbook handler.yaml

PLAY [checking handler functioning] ********************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [starting apache service by adding html content] **************************
changed: [localhost]

RUNNING HANDLER [start_apache] *************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0

[root@workstation ~]# ansible-playbook handler.yaml

PLAY [checking handler functioning] ********************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [starting apache service by adding html content] **************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s