creating role in ansible

Creating a basic role for displaying message of the day 

[root@workstation ~]# vim /etc/ansible/roles/motd/main.yml

– name: use motd role playbook
hosts: all

roles:
– motd

[root@workstation ~]# vim /etc/ansible/roles/motd/defaults/main.yml

system_owner: mohammedrafi
[root@workstation ~]# vim /etc/ansible/roles/motd/tasks/main.yml

– name: deliver motd file
template:
src: templates/motd.j2
dest: /etc/motd
owner: root
group: root
mode: 777
[root@workstation ~]# vim /etc/ansible/roles/motd/templates/motd.j2
this is {{ ansible_hostname }}.
today’s date is {{ ansible_date_time.date }}
you can ask {{ system_owner }} for access
[root@workstation ~]# ansible-playbook –syntax-check /etc/ansible/roles/motd/main.yml

playbook: /etc/ansible/roles/motd/main.yml
[root@workstation ~]# ansible-playbook -C /etc/ansible/roles/motd/main.yml

PLAY [use motd role playbook] **************************************************

TASK [setup] *******************************************************************
ok: [192.168.183.128]
ok: [192.168.183.129]

TASK [motd : deliver motd file] ************************************************
changed: [192.168.183.129]
changed: [192.168.183.128]

PLAY RECAP *********************************************************************
192.168.183.128 : ok=2 changed=1 unreachable=0 failed=0
192.168.183.129 : ok=2 changed=1 unreachable=0 failed=0

[root@workstation ~]# ansible-playbook /etc/ansible/roles/motd/main.yml

PLAY [use motd role playbook] **************************************************

TASK [setup] *******************************************************************
ok: [192.168.183.128]
ok: [192.168.183.129]

TASK [motd : deliver motd file] ************************************************
changed: [192.168.183.129]
changed: [192.168.183.128]

PLAY RECAP *********************************************************************
192.168.183.128 : ok=2 changed=1 unreachable=0 failed=0
192.168.183.129 : ok=2 changed=1 unreachable=0 failed=0

[root@workstation ~]# cat /etc/motd
this is workstation.
today’s date is 2017-01-30
you can ask mohammedrafi for access

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