From 33162a0084be654bf078d5373f7d172b13de6d23 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Wed, 4 Sep 2024 10:50:51 -0400 Subject: [PATCH] working template example --- playbooks/fun_with_templates.yml | 13 +++++++++++++ templates/hosts.j2 | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 playbooks/fun_with_templates.yml create mode 100644 templates/hosts.j2 diff --git a/playbooks/fun_with_templates.yml b/playbooks/fun_with_templates.yml new file mode 100644 index 0000000..49005ec --- /dev/null +++ b/playbooks/fun_with_templates.yml @@ -0,0 +1,13 @@ +--- +- name: template functionality tests + hosts: all + become: yes + tasks: + - name: say hello + debug: + var: hostvars[inventory_hostname]['ansible_facts']['default_ipv4']['address'] + - name: create /etc/hosts.test + template: + src: ../templates/hosts.j2 + dest: /etc/hosts.test + mode: '0644' diff --git a/templates/hosts.j2 b/templates/hosts.j2 new file mode 100644 index 0000000..e62c21e --- /dev/null +++ b/templates/hosts.j2 @@ -0,0 +1,3 @@ +{% for host in groups['all'] %} +{{ hostvars[host]['ansible_facts']['default_ipv4']['address'] }} +{% endfor %}