57 lines
1.8 KiB
YAML
57 lines
1.8 KiB
YAML
---
|
|
- name: IP Address Alias Testing
|
|
hosts: all
|
|
gather_facts: true
|
|
|
|
vars:
|
|
interface_file: /etc/sysconfig/network-scripts/ifcfg-eth0
|
|
default_ipv4: "{{ ansible_default_ipv4['address'] }}"
|
|
iface_cfg_path: /etc/sysconfig/network-scripts
|
|
|
|
tasks:
|
|
- name: Debug ansible_facts
|
|
ansible.builtin.debug:
|
|
var: ansible_facts
|
|
|
|
- name: Debug ansible_interfaces
|
|
ansible.builtin.debug:
|
|
var: ansible_interfaces
|
|
|
|
- name: Loop interfaces
|
|
ansible.builtin.debug:
|
|
msg: "Interface {{ 'ansible_' + item }} detected for {{ inventory_hostname }}"
|
|
loop: "{{ ansible_interfaces }}"
|
|
when:
|
|
- "'lo' not in item"
|
|
|
|
- name: Loop interfaces set_fact
|
|
ansible.builtin.set_fact:
|
|
# host_interfaces: "{inventory_hostname: {{ 'ansible_' + item }}"
|
|
host_interfaces: "{{ host_interfaces | default([]) | combine({inventory_hostname + '_' + item: 'ansible_' + item}) }}"
|
|
loop: "{{ ansible_interfaces }}"
|
|
when:
|
|
- "'lo' not in item"
|
|
|
|
- name: Debug host_interfaces
|
|
ansible.builtin.debug:
|
|
var: host_interfaces
|
|
|
|
- name: What will this do
|
|
ansible.builtin.debug:
|
|
msg: "hello {{ item['value'] }}"
|
|
loop: "{{ host_interfaces | dict2items }}"
|
|
|
|
- name: Detect if the default interface has IP aliases defined
|
|
ansible.builtin.debug:
|
|
msg: "{{ inventory_hostname }} has IP aliases defined for {{ item.value }}."
|
|
loop: "{{ host_interfaces | dict2items }}"
|
|
loop_control:
|
|
label: "{{ item['key'] }}"
|
|
when:
|
|
- hostvars[inventory_hostname][item.value]['ipv4_secondaries'] is defined
|
|
# when:
|
|
# - ansible_facts[item['value']]['ipv4_secondaries'] is defined
|
|
# when:
|
|
# - "item.value['ipv4_secondaries'] is defined"
|
|
|