-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lineinfile not working with insertbefore: BOF
in Ansible 2.5.0
#38219
Comments
Files identified in the description: If these files are inaccurate, please update the |
Full playbook to reproduce:
Error:
|
The interesting behavior I see is that running this again on a file that has previously been updated to insert a line at BOF using insertbefore causes a second line to be inserted on the line just above the last line in the file. |
Yes also it added the line at the end of a file instead of at the beginning... very weird |
|
I can also reproduce this behavior:
6-line file produced above
7-line file produced above and read by
|
Hey, this has been open for more than a month. It's breaking playbooks. What's the story? |
I am working on a fix. Apologies for the delay. I see why this is happening but it's at odds with the changes I made in #36474. I'm trying to balance the two. I've also added tests for this to prevent a regression. |
This may actually be more related to what was done in #33393. Anyway, still working through it. |
I believe I have it fixed. PR coming shortly. |
Please test with #41767 and see if that resolves your issue. Thank you for reporting this. |
Thanks @samdoran, looks like this change has been included in Ansible 2.6.0, and fixes my issue. |
@craigfrancis Thanks for the follow up confirmation. Glad this fixed your issue. |
ISSUE TYPE
COMPONENT NAME
lineinfile
ANSIBLE VERSION
ansible 2.5.0
config file = /Volumes/WebServer/Projects/ansible.local/ansible.cfg
configured module search path = [u'/Users/craig/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Python/2.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.10 (default, Oct 6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
CONFIGURATION
ANSIBLE_PIPELINING(/Users/craig/Downloads/ansible/ansible.cfg) = True
DEFAULT_HOST_LIST(/Users/craig/Downloads/ansible/ansible.cfg) = [u'/Users/craig/Downloads/ansible/inventory']
RETRY_FILES_ENABLED(/Users/craig/Downloads/ansible/ansible.cfg) = False
OS / ENVIRONMENT
MacOS 10.13.4 (17E199)
SUMMARY
When looking for a line that is at the beginning of the file (BOF), it doesn't always detect it exists, or insert it in the correct location.
STEPS TO REPRODUCE
Create the
dest
file so it's empty: First run, the line is added (good); Second time, "An exception occurred during task execution" ... "The error was: IndexError: list index out of range".Replace the contents of this file with a newline, followed by some text (i.e. 2 lines, but the first line is blank): First run, the line is added (good); Second time the line is added again.
Replace the contents of this file with 3 lines of random text: First run, the line is added (good); Second time the line is added again (on the 4th line).
EXPECTED RESULTS
When the line is missing, it should be added to the file... but once it exists, it shouldn't be added again.
ACTUAL RESULTS
Depends on the contents of the file before hand.
Video of results
The text was updated successfully, but these errors were encountered: