working template example

This commit is contained in:
Ibrahim Mkusa 2024-09-04 10:50:51 -04:00
parent 4536536f24
commit 33162a0084
2 changed files with 16 additions and 0 deletions

View File

@ -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'

3
templates/hosts.j2 Normal file
View File

@ -0,0 +1,3 @@
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_facts']['default_ipv4']['address'] }}
{% endfor %}