mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2025-12-14 13:54:37 +03:00
clean up /etc/hosts file if populate_inventory_to_hosts_file is false (#10144)
* de-populate hosts file if populate_inventory_to_hosts_file is false keep newline * fix when condition
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Hosts | update inventory in hosts file
|
- name: Hosts | create hosts list from inventory
|
||||||
when: populate_inventory_to_hosts_file
|
|
||||||
block:
|
|
||||||
- name: Hosts | create list from inventory
|
|
||||||
set_fact:
|
set_fact:
|
||||||
etc_hosts_inventory_block: |-
|
etc_hosts_inventory_block: |-
|
||||||
{% for item in (groups['k8s_cluster'] + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique -%}
|
{% for item in (groups['k8s_cluster'] + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique -%}
|
||||||
@@ -17,11 +14,11 @@
|
|||||||
delegate_facts: yes
|
delegate_facts: yes
|
||||||
run_once: yes
|
run_once: yes
|
||||||
|
|
||||||
- name: Hosts | populate inventory into hosts file
|
- name: Hosts | populate inventory into hosts file
|
||||||
blockinfile:
|
blockinfile:
|
||||||
path: /etc/hosts
|
path: /etc/hosts
|
||||||
block: "{{ hostvars.localhost.etc_hosts_inventory_block }}"
|
block: "{{ hostvars.localhost.etc_hosts_inventory_block }}"
|
||||||
state: present
|
state: "{{ 'present' if populate_inventory_to_hosts_file else 'absent' }}"
|
||||||
create: yes
|
create: yes
|
||||||
backup: yes
|
backup: yes
|
||||||
unsafe_writes: yes
|
unsafe_writes: yes
|
||||||
|
|||||||
Reference in New Issue
Block a user