From e3ebabc3b00260a63bfb2dcf6266f98315ada4e2 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Wed, 14 Sep 2016 18:14:26 +0300 Subject: [PATCH] switch /etc/hosts to use blockinfile --- roles/kubernetes/preinstall/tasks/etchosts.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/roles/kubernetes/preinstall/tasks/etchosts.yml b/roles/kubernetes/preinstall/tasks/etchosts.yml index dd8562b8c..6f21ffa8f 100644 --- a/roles/kubernetes/preinstall/tasks/etchosts.yml +++ b/roles/kubernetes/preinstall/tasks/etchosts.yml @@ -1,14 +1,15 @@ --- - name: Hosts | populate inventory into hosts file - lineinfile: + blockinfile: dest: /etc/hosts - regexp: "^{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item].ansible_default_ipv4.address)) }} {{ item }}$" - line: "{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item].ansible_default_ipv4.address)) }} {{ item }}" + block: |- + {% for item in groups['all'] -%} + {{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item].ansible_default_ipv4.address)) }} {{ item }} + {% endfor %} state: present create: yes backup: yes - when: hostvars[item].ansible_default_ipv4.address is defined - with_items: "{{ groups['all'] }}" + marker: "# Ansible inventory hosts {mark}" - name: Hosts | populate kubernetes loadbalancer address into hosts file lineinfile: