From 64aee066918405f96536de13249afcbd19c6574f Mon Sep 17 00:00:00 2001 From: Cedric Girard Date: Wed, 1 Aug 2018 15:50:48 +0200 Subject: [PATCH] 7th exercise: delegation --- 70.Delegate/70.Delegate.md | 25 +++++++++++++++++++++++++ 70.Delegate/solution/solution.yml | 11 +++++++++++ 70.Delegate/solution/template/report.j2 | 10 ++++++++++ 3 files changed, 46 insertions(+) create mode 100644 70.Delegate/70.Delegate.md create mode 100644 70.Delegate/solution/solution.yml create mode 100644 70.Delegate/solution/template/report.j2 diff --git a/70.Delegate/70.Delegate.md b/70.Delegate/70.Delegate.md new file mode 100644 index 0000000..99f7144 --- /dev/null +++ b/70.Delegate/70.Delegate.md @@ -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 + + + + + +
FQDNOSArchitectureDefault IPv4
"FQDN for host 1""OS for host 1""Architecture for host 1""Default IPv4 for host 1"
+ + +``` +* 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` diff --git a/70.Delegate/solution/solution.yml b/70.Delegate/solution/solution.yml new file mode 100644 index 0000000..9486c77 --- /dev/null +++ b/70.Delegate/solution/solution.yml @@ -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: diff --git a/70.Delegate/solution/template/report.j2 b/70.Delegate/solution/template/report.j2 new file mode 100644 index 0000000..98636fe --- /dev/null +++ b/70.Delegate/solution/template/report.j2 @@ -0,0 +1,10 @@ + + + + + {% for host in play_hosts | sort %} + + {% endfor %} +
FQDNOSArchitectureDefault IPv4
{{ hostvars[host]['ansible_fqdn'] }}{{ hostvars[host]['ansible_os_family'] }}{{ hostvars[host]['ansible_architecture'] }}{{ hostvars[host]['ansible_default_ipv4'].address }}
+ +