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.23]
ok: [192.168.1.22]
TASK [motd : deliver motd file] ************************************************
changed: [192.168.1.22]
changed: [192.168.1.23]
PLAY RECAP *********************************************************************
192.168.1.23 : ok=2 changed=1 unreachable=0 failed=0
192.168.1.22 : 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.23]
ok: [192.168.1.22]
TASK [motd : deliver motd file] ************************************************
changed: [192.168.1.22]
changed: [192.168.1.23]
PLAY RECAP *********************************************************************
192.168.1.23 : ok=2 changed=1 unreachable=0 failed=0
192.168.1.22 : ok=2 changed=1 unreachable=0 failed=0
[root@workstation ~]# cat /etc/motd
this is workstation.
today’s date is 2018-01-30
you can ask rmohan for access
Recent Comments