7th exercise: delegation
This commit is contained in:
parent
5298185d97
commit
64aee06691
3 changed files with 46 additions and 0 deletions
25
70.Delegate/70.Delegate.md
Normal file
25
70.Delegate/70.Delegate.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# 70 - Delegate
|
||||
|
||||
This exercise makes you use delegation.
|
||||
|
||||
## Playbook creation
|
||||
Create a playbook following the given specs:
|
||||
* Gather facts on host group `lab`
|
||||
* Use these facts to create an HTML report on localhost
|
||||
* The HTML report should be formated like this:
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
<table>
|
||||
<tr><td>FQDN</td><td>OS</td><td>Architecture</td><td>Default IPv4</td></tr>
|
||||
<tr><td>"FQDN for host 1"</td><td>"OS for host 1"</td><td>"Architecture for host 1"</td><td>"Default IPv4 for host 1"</td></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
* It should contains one line for each host in the group `lab`
|
||||
|
||||
## Validation
|
||||
Run the playbook and then validate the html content is as you expected opening it in your browser.
|
||||
|
||||
There is a working playbook in `solution/solution.yml`
|
11
70.Delegate/solution/solution.yml
Normal file
11
70.Delegate/solution/solution.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
- hosts: lab
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Create html report
|
||||
template:
|
||||
src: template/report.j2
|
||||
dest: /tmp/report.html
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
|
||||
# vim: set ft=yaml sw=2 et:
|
10
70.Delegate/solution/template/report.j2
Normal file
10
70.Delegate/solution/template/report.j2
Normal file
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<body>
|
||||
<table>
|
||||
<tr><td>FQDN</td><td>OS</td><td>Architecture</td><td>Default IPv4</td></tr>
|
||||
{% for host in play_hosts | sort %}
|
||||
<tr><td>{{ hostvars[host]['ansible_fqdn'] }}</td><td>{{ hostvars[host]['ansible_os_family'] }}</td><td>{{ hostvars[host]['ansible_architecture'] }}</td><td>{{ hostvars[host]['ansible_default_ipv4'].address }}</td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue