{"id":7329,"date":"2018-04-06T09:05:54","date_gmt":"2018-04-06T01:05:54","guid":{"rendered":"http:\/\/rmohan.com\/?p=7329"},"modified":"2018-04-06T09:06:08","modified_gmt":"2018-04-06T01:06:08","slug":"handlers-register-in-ansible","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7329","title":{"rendered":"HANDLERS &#038; register in ansible"},"content":{"rendered":"<p>HANDLERS &amp; register in ansible<\/p>\n<p>[root@workstation ~]# vim register.yaml<br \/>\n\u2014<br \/>\n\u2013 name: checking the register module functionality<br \/>\nhosts: localhost<br \/>\ntasks:<br \/>\n\u2013 name:<br \/>\ncommand: ps<br \/>\nregister: output<br \/>\n\u2013 debug: msg=\u201d{{ output.stdout }}\u201d<br \/>\n====================================================<br \/>\n[root@workstation ~]# ansible-playbook \u2013syntax-check register.yaml<\/p>\n<p>playbook: register.yaml<\/p>\n<p>[root@workstation ~]# ansible-playbook register.yaml<\/p>\n<p>PLAY [checking the register module functionality] ******************************<\/p>\n<p>TASK [setup] *******************************************************************<br \/>\nok: [localhost]<\/p>\n<p>TASK [command] *****************************************************************<br \/>\nchanged: [localhost]<\/p>\n<p>TASK [debug] *******************************************************************<br \/>\nok: [localhost] =&gt; {<br \/>\n\u201cmsg\u201d: \u201d 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\u201d<br \/>\n}<\/p>\n<p>PLAY RECAP *********************************************************************<br \/>\nlocalhost : ok=3 changed=1 unreachable=0 failed=0<br \/>\n====================================================<br \/>\n[root@workstation ~]# vim register.yaml<br \/>\n\u2014<br \/>\n\u2013 name: checking the register module functionality<br \/>\nhosts: localhost<br \/>\ntasks:<br \/>\n\u2013 name:<br \/>\nshell: \u201cps -aux | grep ansible\u201d<br \/>\nregister: output<br \/>\n\u2013 debug: msg={{ output.stdout }}<br \/>\n[root@workstation ~]# ansible-playbook register.yaml<\/p>\n<p>PLAY [checking the register module functionality] ******************************<\/p>\n<p>TASK [setup] *******************************************************************<br \/>\nok: [localhost]<\/p>\n<p>TASK [command] *****************************************************************<br \/>\nchanged: [localhost]<\/p>\n<p>TASK [debug] *******************************************************************<br \/>\nok: [localhost] =&gt; {<br \/>\n\u201cmsg\u201d: \u201croot 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 \\\u201d\/root\/.ansible\/tmp\/ansible-tmp-1485725579.35-37718783810169\/\\\u201d &gt; \/dev\/null 2&gt;&amp;1 &amp;&amp; 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\u201d<br \/>\n}<\/p>\n<p>PLAY RECAP *********************************************************************<br \/>\nlocalhost : ok=3 changed=1 unreachable=0 failed=0<br \/>\n====================================================<\/p>\n<p>[root@workstation ~]# vim handler.yaml<br \/>\n\u2014<br \/>\n\u2013 name: checking handler functioning<br \/>\nhosts: localhost<br \/>\ntasks:<br \/>\n\u2013 name: starting apache service by adding html content<br \/>\ncopy:<br \/>\nsrc: \/root\/index.html<br \/>\ndest: \/var\/www\/html\/index.html<br \/>\nnotify:<br \/>\n\u2013 start_apache<br \/>\nhandlers:<br \/>\n\u2013 name: start_apache<br \/>\nservice:<br \/>\nname: httpd<br \/>\nstate: started<br \/>\n[root@workstation ~]# vim \/root\/index.html<br \/>\nthis for checking handler<\/p>\n<p>[root@workstation ~]# ansible-playbook \u2013syntax-check handler.yaml<\/p>\n<p>playbook: handler.yaml<\/p>\n<p>[root@workstation ~]# ansible-playbook handler.yaml<\/p>\n<p>PLAY [checking handler functioning] ********************************************<\/p>\n<p>TASK [setup] *******************************************************************<br \/>\nok: [localhost]<\/p>\n<p>TASK [starting apache service by adding html content] **************************<br \/>\nchanged: [localhost]<\/p>\n<p>RUNNING HANDLER [start_apache] *************************************************<br \/>\nchanged: [localhost]<\/p>\n<p>PLAY RECAP *********************************************************************<br \/>\nlocalhost : ok=3 changed=2 unreachable=0 failed=0<\/p>\n<p>[root@workstation ~]# ansible-playbook handler.yaml<\/p>\n<p>PLAY [checking handler functioning] ********************************************<\/p>\n<p>TASK [setup] *******************************************************************<br \/>\nok: [localhost]<\/p>\n<p>TASK [starting apache service by adding html content] **************************<br \/>\nok: [localhost]<\/p>\n<p>PLAY RECAP *********************************************************************<br \/>\nlocalhost : ok=2 changed=0 unreachable=0 failed=0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HANDLERS &amp; register in ansible<\/p>\n<p>[root@workstation ~]# vim register.yaml \u2014 \u2013 name: checking the register module functionality hosts: localhost tasks: \u2013 name: command: ps register: output \u2013 debug: msg=\u201d{{ output.stdout }}\u201d ==================================================== [root@workstation ~]# ansible-playbook \u2013syntax-check register.yaml<\/p>\n<p>playbook: register.yaml<\/p>\n<p>[root@workstation ~]# ansible-playbook register.yaml<\/p>\n<p>PLAY [checking the register module functionality] ******************************<\/p>\n<p>TASK [setup] ******************************************************************* ok: [localhost]<\/p>\n<p> [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7329"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7329"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7329\/revisions"}],"predecessor-version":[{"id":7331,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7329\/revisions\/7331"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}