5th exercise: jinja templating
This commit is contained in:
parent
a06b675165
commit
efb254f2c5
3 changed files with 40 additions and 0 deletions
25
50.Template/50.Template.md
Normal file
25
50.Template/50.Template.md
Normal 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`
|
10
50.Template/solution/solution.yml
Normal file
10
50.Template/solution/solution.yml
Normal 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:
|
5
50.Template/solution/template/motd.j2
Normal file
5
50.Template/solution/template/motd.j2
Normal 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.
|
||||
-----------------------------/
|
Loading…
Reference in a new issue