From 7847b4185eb767f28dfd8a63e513d04aa6c4e2b5 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Mon, 22 Feb 2016 16:13:32 +0100 Subject: [PATCH] Do not use atomic file updates for hosts_file Use shell/copy magic to w/a https://github.com/docker/docker/issues/9295 Related-bug: #1547587 Change-Id: I881d362968a10d816cbd368cb185900dfaa0b3bc Signed-off-by: Bogdan Dobrelya --- resources/hosts_file/1.0.0/actions/run.yaml | 19 ++++++++++++++++++- .../hosts_file/1.0.0/actions/update.yaml | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/resources/hosts_file/1.0.0/actions/run.yaml b/resources/hosts_file/1.0.0/actions/run.yaml index 76e05c8..6b9fb12 100644 --- a/resources/hosts_file/1.0.0/actions/run.yaml +++ b/resources/hosts_file/1.0.0/actions/run.yaml @@ -1,11 +1,28 @@ - hosts: [{{host}}] become: yes tasks: + # those shell/copy below are hacky solution for https://github.com/docker/docker/issues/9295 + - shell: md5sum /etc/hosts + register: fence_token + + - copy: src=/etc/hosts dest=/tmp/hosts + {% for val in hosts %} - name: Create hosts entries for {{val['name']}} => {{val['ip']}} lineinfile: - dest: /etc/hosts + dest: /tmp/hosts regexp: ".*{{val['name']}}$" line: "{{val['ip']}} {{val['name']}}" state: present {% endfor %} + + - shell: md5sum /etc/hosts + register: current_state + + - shell: cp -f /tmp/hosts /etc/hosts + when: current_state.stdout.find(fence_token.stdout) != -1 + + - file: path=/tmp/hosts state=absent + + - shell: /bin/false + when: current_state.stdout.find(fence_token.stdout) == -1 diff --git a/resources/hosts_file/1.0.0/actions/update.yaml b/resources/hosts_file/1.0.0/actions/update.yaml index 76e05c8..6b9fb12 100644 --- a/resources/hosts_file/1.0.0/actions/update.yaml +++ b/resources/hosts_file/1.0.0/actions/update.yaml @@ -1,11 +1,28 @@ - hosts: [{{host}}] become: yes tasks: + # those shell/copy below are hacky solution for https://github.com/docker/docker/issues/9295 + - shell: md5sum /etc/hosts + register: fence_token + + - copy: src=/etc/hosts dest=/tmp/hosts + {% for val in hosts %} - name: Create hosts entries for {{val['name']}} => {{val['ip']}} lineinfile: - dest: /etc/hosts + dest: /tmp/hosts regexp: ".*{{val['name']}}$" line: "{{val['ip']}} {{val['name']}}" state: present {% endfor %} + + - shell: md5sum /etc/hosts + register: current_state + + - shell: cp -f /tmp/hosts /etc/hosts + when: current_state.stdout.find(fence_token.stdout) != -1 + + - file: path=/tmp/hosts state=absent + + - shell: /bin/false + when: current_state.stdout.find(fence_token.stdout) == -1