Bogdan Dobrelya 7847b4185e 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 <bdobrelia@mirantis.com>
2016-02-25 15:21:03 +01:00

29 lines
806 B
YAML

- 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: /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