working on host loop

This commit is contained in:
2025-03-27 17:37:01 -05:00
parent bda585fcd5
commit b8609db119
6 changed files with 40 additions and 32 deletions

View File

@@ -19,11 +19,19 @@
dest: homelab/terraform/dns/provider.tf
mode: '0644'
- name: Show all the hosts in the inventory
when: "{{ hostvars[groups['all'][ {{ item }} ]['ip_address'] }}" is defined
ansible.builtin.debug:
msg: "{{ hostvars[item].ip_address }}"
loop: "{{ query('inventory_hostnames', 'all') }}"
- name: Loop through all hosts
vars:
my_hosts: "{{ query('inventory_hostnames', 'all') }}"
# ansible.builtin.debug:
# msg: "Host {{ item }} has IP address: {{ hostvars[my_hosts[my_idx]].ip_address | default('No IP address defined') }}"
ansible.builtin.template:
src: templates/dns.tf.j2
dest: homelab/terraform/dns/{{ item }}.tf
mode: '0644'
when: hostvars[my_hosts[my_idx]].ip_address is defined
loop: "{{ my_hosts }}"
loop_control:
index_var: my_idx
# - name: Loop through all hosts
# block: