I have a simple host inventory :
server1.com
server2.com
server3.com
server4.com
I run some tasks on this inventory and at the end, create file and insert line with lineinfile on a shared folder between all hosts:
- name: "END - Insert infos in /sharefolder/{{ inventory_hostname|upper }}"
lineinfile:
path: "/sharefolder/{{ inventory_hostname|upper }}"
state: present
create: yes
regexp: "^{{ inventory_hostname }}"
line: "{{ inventory_hostname|upper }};This is my line"
owner: owner
group: group
mode: '0644'
Everything is fine when I run the playbook:
PLAY RECAP **************************************************************************************************************************
server1.com : ok=14 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server2.com : ok=14 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server3.com : ok=14 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server4.com : ok=14 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
But when I look into my shared folder, I don't have the file from the last host:
$ ls -l /sharefolder/
-rw-r--r-- 1 owner group 123 Apr 3 11:48 SERVER1.COM
-rw-r--r-- 1 owner group 105 Apr 3 11:48 SERVER2.COM
-rw-r--r-- 1 owner group 123 Apr 3 11:48 SERVER3.COM
I tested with several hosts, adding blank lines at the end of host inventory, and with option --forks=1
when launching the playbook, but issue is still there. Option -vvv
returns that everything is OK, file has been created and line added for the last hosts, but it isn't the case.