5th exercise: jinja templating

This commit is contained in:
Cedric Girard 2018-08-01 15:16:22 +02:00
parent a06b675165
commit efb254f2c5
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# 50 - Template
This playbook makes you use Jinja templating to deploy custom motd.
## Template and Playbook Creation
First write a Jinja template file following the given specs:
* Contains the following content:
```
/-----------------------------
Welcome to the ansible managed host: <hostname>
Please use Ansible playbooks instead of doing manual modifications on the system.
-----------------------------/
```
* Ensure that you use the correct Jinja mechanism to allow replacement of `<hostname` by the corresponding value from the inventory (IP address is OK, depending of your host file).
Then write a playbook following the given specs:
* Run on host group `lab`
* Deploys the instantiated Jinja template file previously created to `/etc/motd`
## Validation
Run the playbook and then try to connect to each host to validate you see the customized banner on ssh connection.
There is a working playbook in `solution/solution.yml`

View File

@ -0,0 +1,10 @@
- hosts: lab
gather_facts: false
tasks:
- name: Deploy MOTD
template:
src: template/motd.j2
dest: /etc/motd
become: true
# vim: set ft=yaml sw=2 et:

View File

@ -0,0 +1,5 @@
/-----------------------------
Welcome to the ansible managed host: {{ ansible_host }}
Please use Ansible playbooks instead of doing manual modifications on the system.
-----------------------------/