Calculate inventory list only once (#5956)
This commit is contained in:
parent
54debdbda2
commit
b09fe64ff1
1 changed files with 13 additions and 6 deletions
|
@ -1,14 +1,21 @@
|
||||||
---
|
---
|
||||||
- name: Hosts | populate inventory into hosts file
|
- name: Hosts | create list from inventory
|
||||||
blockinfile:
|
set_fact:
|
||||||
path: /etc/hosts
|
etc_hosts_inventory_block: |-
|
||||||
block: |-
|
|
||||||
{% for item in (groups['k8s-cluster'] + groups['etcd'] + groups['calico-rr']|default([]))|unique -%}
|
{% for item in (groups['k8s-cluster'] + groups['etcd'] + groups['calico-rr']|default([]))|unique -%}
|
||||||
{% if 'access_ip' in hostvars[item] or 'ip' in hostvars[item] or fallback_ips[item] != "skip" -%}
|
{% if 'access_ip' in hostvars[item] or 'ip' in hostvars[item] or 'ansible_default_ipv4' in hostvars[item] -%}
|
||||||
{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(fallback_ips[item])) }}
|
{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item]['ansible_default_ipv4']['address'])) }}
|
||||||
{%- if ('ansible_hostname' in hostvars[item] and item != hostvars[item]['ansible_hostname']) %} {{ hostvars[item]['ansible_hostname'] }}.{{ dns_domain }} {{ hostvars[item]['ansible_hostname'] }}{% endif %} {{ item }}.{{ dns_domain }} {{ item }}
|
{%- if ('ansible_hostname' in hostvars[item] and item != hostvars[item]['ansible_hostname']) %} {{ hostvars[item]['ansible_hostname'] }}.{{ dns_domain }} {{ hostvars[item]['ansible_hostname'] }}{% endif %} {{ item }}.{{ dns_domain }} {{ item }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
delegate_to: localhost
|
||||||
|
delegate_facts: yes
|
||||||
|
run_once: yes
|
||||||
|
|
||||||
|
- name: Hosts | populate inventory into hosts file
|
||||||
|
blockinfile:
|
||||||
|
path: /etc/hosts
|
||||||
|
block: "{{ hostvars.localhost.etc_hosts_inventory_block }}"
|
||||||
state: present
|
state: present
|
||||||
create: yes
|
create: yes
|
||||||
backup: yes
|
backup: yes
|
||||||
|
|
Loading…
Reference in a new issue