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 %}