mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2025-12-14 05:45:06 +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
|
||||
when: populate_inventory_to_hosts_file
|
||||
block:
|
||||
- name: Hosts | create list from inventory
|
||||
- name: Hosts | create hosts list from inventory
|
||||
set_fact:
|
||||
etc_hosts_inventory_block: |-
|
||||
{% for item in (groups['k8s_cluster'] + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique -%}
|
||||
@@ -21,7 +18,7 @@
|
||||
blockinfile:
|
||||
path: /etc/hosts
|
||||
block: "{{ hostvars.localhost.etc_hosts_inventory_block }}"
|
||||
state: present
|
||||
state: "{{ 'present' if populate_inventory_to_hosts_file else 'absent' }}"
|
||||
create: yes
|
||||
backup: yes
|
||||
unsafe_writes: yes
|
||||
|
||||
Reference in New Issue
Block a user