{"id":7332,"date":"2018-04-06T09:08:44","date_gmt":"2018-04-06T01:08:44","guid":{"rendered":"http:\/\/rmohan.com\/?p=7332"},"modified":"2018-04-06T09:09:10","modified_gmt":"2018-04-06T01:09:10","slug":"creating-role-in-ansible-2","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7332","title":{"rendered":"Creating role in ansible"},"content":{"rendered":"<p><strong>Creating a basic role for displaying message of the day<\/strong><\/p>\n<p>[root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/main.yml<br \/>\n\u2014<br \/>\n\u2013 name: use motd role playbook<br \/>\nhosts: all<\/p>\n<p>roles:<br \/>\n\u2013 motd<\/p>\n<p>[root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/defaults\/main.yml<br \/>\n\u2014<br \/>\nsystem_owner: rmohan<br \/>\n[root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/tasks\/main.yml<br \/>\n\u2014<br \/>\n\u2013 name: deliver motd file<br \/>\ntemplate:<br \/>\nsrc: templates\/motd.j2<br \/>\ndest: \/etc\/motd<br \/>\nowner: root<br \/>\ngroup: root<br \/>\nmode: 777<br \/>\n[root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/templates\/motd.j2<br \/>\nthis is {{ ansible_hostname }}.<br \/>\ntoday\u2019s date is {{ ansible_date_time.date }}<br \/>\nyou can ask {{ system_owner }} for access<br \/>\n[root@workstation ~]# ansible-playbook \u2013syntax-check \/etc\/ansible\/roles\/motd\/main.yml<\/p>\n<p>playbook: \/etc\/ansible\/roles\/motd\/main.yml<br \/>\n[root@workstation ~]# ansible-playbook -C \/etc\/ansible\/roles\/motd\/main.yml<\/p>\n<p>PLAY [use motd role playbook] **************************************************<\/p>\n<p>TASK [setup] *******************************************************************<br \/>\nok: [192.168.1.22]<br \/>\nok: [192.168.1.23]<\/p>\n<p>TASK [motd : deliver motd file] ************************************************<br \/>\nchanged: [192.168.1.23]<br \/>\nchanged: [192.168.1.22]<\/p>\n<p>PLAY RECAP *********************************************************************<br \/>\n192.168.1.22 : ok=2 changed=1 unreachable=0 failed=0<br \/>\n192.168.1.23 : ok=2 changed=1 unreachable=0 failed=0<\/p>\n<p>[root@workstation ~]# ansible-playbook \/etc\/ansible\/roles\/motd\/main.yml<\/p>\n<p>PLAY [use motd role playbook] **************************************************<\/p>\n<p>TASK [setup] *******************************************************************<br \/>\nok: [192.168.1.22]<br \/>\nok: [192.168.1.23]<\/p>\n<p>TASK [motd : deliver motd file] ************************************************<br \/>\nchanged: [192.168.1.23]<br \/>\nchanged: [192.168.1.22]<\/p>\n<p>PLAY RECAP *********************************************************************<br \/>\n192.168.1.22 : ok=2 changed=1 unreachable=0 failed=0<br \/>\n192.168.1.23 : ok=2 changed=1 unreachable=0 failed=0<\/p>\n<p>[root@workstation ~]# cat \/etc\/motd<br \/>\nthis is workstation.<br \/>\ntoday\u2019s date is 2017-01-30<br \/>\nyou can ask rmohan for access<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating a basic role for displaying message of the day<\/p>\n<p>[root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/main.yml \u2014 \u2013 name: use motd role playbook hosts: all<\/p>\n<p>roles: \u2013 motd<\/p>\n<p>[root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/defaults\/main.yml \u2014 system_owner: rmohan [root@workstation ~]# vim \/etc\/ansible\/roles\/motd\/tasks\/main.yml \u2014 \u2013 name: deliver motd file template: src: templates\/motd.j2 dest: \/etc\/motd owner: root group: root mode: 777 [root@workstation [&#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\/7332"}],"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=7332"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7332\/revisions"}],"predecessor-version":[{"id":7334,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7332\/revisions\/7334"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}