working on host loop
This commit is contained in:
@@ -27,6 +27,8 @@ This implementation is built on easily accessible consumer based hardware and wi
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
|
- Ansible user created
|
||||||
|
- Ansible configured
|
||||||
- [Networking](docs/networks.md)
|
- [Networking](docs/networks.md)
|
||||||
- [Proxmox](docs/proxmox.md) (In my homelab, internal DNS, identity manangement, and ipxe are hosted here.)
|
- [Proxmox](docs/proxmox.md) (In my homelab, internal DNS, identity manangement, and ipxe are hosted here.)
|
||||||
- Matchbox
|
- Matchbox
|
||||||
|
|||||||
@@ -19,11 +19,19 @@
|
|||||||
dest: homelab/terraform/dns/provider.tf
|
dest: homelab/terraform/dns/provider.tf
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
|
||||||
- name: Show all the hosts in the inventory
|
- name: Loop through all hosts
|
||||||
when: "{{ hostvars[groups['all'][ {{ item }} ]['ip_address'] }}" is defined
|
vars:
|
||||||
ansible.builtin.debug:
|
my_hosts: "{{ query('inventory_hostnames', 'all') }}"
|
||||||
msg: "{{ hostvars[item].ip_address }}"
|
# ansible.builtin.debug:
|
||||||
loop: "{{ query('inventory_hostnames', 'all') }}"
|
# 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
|
# - name: Loop through all hosts
|
||||||
# block:
|
# block:
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
// Terraform DNS entry template
|
|
||||||
|
|
||||||
resource "freeipa_dns_record" "ocp-hub" {
|
|
||||||
zone_name = "int.mk-labs.cloud."
|
|
||||||
name = "ocp-hub"
|
|
||||||
type = "A"
|
|
||||||
records = [
|
|
||||||
"10.1.71.10",
|
|
||||||
]
|
|
||||||
ttl = 60
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// Terraform DNS entry template
|
|
||||||
|
|
||||||
resource "freeipa_dns_record" "pve01" {
|
|
||||||
zone_name = "int.mk-labs.cloud."
|
|
||||||
name = "pve01"
|
|
||||||
type = "A"
|
|
||||||
records = [
|
|
||||||
"10.1.71.51",
|
|
||||||
]
|
|
||||||
ttl = 60
|
|
||||||
}
|
|
||||||
14
print_ips.yml
Normal file
14
print_ips.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
- name: Print host IP addresses
|
||||||
|
hosts: infra01
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
my_hosts: "{{ query('inventory_hostnames', 'all') }}"
|
||||||
|
tasks:
|
||||||
|
- name: Loop through all hosts
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Host {{ item }} has IP address: {{ hostvars[my_hosts[my_idx]].ip_address | default('No IP address defined') }}"
|
||||||
|
when: hostvars[my_hosts[my_idx]].ip_address is defined
|
||||||
|
loop: "{{ my_hosts }}"
|
||||||
|
loop_control:
|
||||||
|
index_var: my_idx
|
||||||
16
test.yml
16
test.yml
@@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
- name: Run all tasks necessary to configure matchbox to install the cluster
|
- name: Run all tasks necessary to configure matchbox to install the cluster
|
||||||
hosts: infra01
|
hosts: all
|
||||||
#connection: local
|
#connection: local
|
||||||
gather_facts: true
|
gather_facts: false
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
# - name: Print vars for debugging
|
# - name: Print vars for debugging
|
||||||
@@ -21,6 +21,12 @@
|
|||||||
# ansible.builtin.debug:
|
# ansible.builtin.debug:
|
||||||
# msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }}
|
# msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }}
|
||||||
|
|
||||||
- name: Print all available facts
|
# - name: Print all available facts
|
||||||
ansible.builtin.debug:
|
# ansible.builtin.debug:
|
||||||
var: ansible_facts
|
# var: ansible_facts
|
||||||
|
|
||||||
|
|
||||||
|
- name: Print host IP address if defined
|
||||||
|
debug:
|
||||||
|
msg: "Host {{ inventory_hostname }} has IP address: {{ hostvars[inventory_hostname].ip_address | default('Not defined') }}"
|
||||||
|
when: hostvars[inventory_hostname].ip_address is defined
|
||||||
Reference in New Issue
Block a user