April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

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: rmohan
[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.1.22]
ok: [192.168.1.23]

TASK [motd : deliver motd file] ************************************************
changed: [192.168.1.23]
changed: [192.168.1.22]

PLAY RECAP *********************************************************************
192.168.1.22 : ok=2 changed=1 unreachable=0 failed=0
192.168.1.23 : 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.1.22]
ok: [192.168.1.23]

TASK [motd : deliver motd file] ************************************************
changed: [192.168.1.23]
changed: [192.168.1.22]

PLAY RECAP *********************************************************************
192.168.1.22 : ok=2 changed=1 unreachable=0 failed=0
192.168.1.23 : 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 rmohan for access

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>