'Ansible Tower - Module lineinfile - Issue: Missing lines
I'm using ansible tower and configured to run forks = 250.
My tasks is simple, it writes in a file data extracted from hosts like 4000 hosts.
example:
- name: creating report
lineinfile: dest="reports/{{ report_name }}.csv" line="{{ inventory_hostname }},{{ item }}"
insertafter=EOF create=yes
with_items: "{{ report_result.stdout_lines | trim }}"
That works well, but recently i have noticed lines missing like 400 hosts.
There is nothing wrong with those hosts, so the only lead i have is that the module lineinfile
has its limitations while writing that many lines in a file.
I'm wondering if anybody here have or had this problem before and any alternatives. thanks!
Solution 1:[1]
Not sure this is a limitation on lineinfile
but reducing the forks from 250 to default fixed the problem.
Solution 2:[2]
I am running Ansible core and have noticed a similar issue. Running something like the following even on a small # of hosts (less than 10) causes lines to be missing:
- name: "Generate Summary Report Line"
lineinfile:
path: "{{ report_sum_file }}"
line: "some text that is different per {{host}}"
delegate_to: localhost
The only way I could work around this was to create a separate play for that task with serial: 1
which looks like:
- name: Write Report Lines
hosts: all
gather_facts: no
serial: 1
tasks:
- name: "Generate Summary Report Line"
lineinfile:
path: "{{ report_sum_file }}"
line: "some text that is different per {{host}}"
delegate_to: localhost
Solution 3:[3]
Adding serial: 1
is the only thing worked for me as well
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | eduprado |
Solution 2 | user12177216 |
Solution 3 | Ivan Kalytovskyy |