Skip to content
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

Skip if insertbefore is using BOF until later in the module #41767

Merged

Conversation

samdoran
Copy link
Contributor

SUMMARY

When a regexp was not provided and insertbefore/insertafter were used, a line match anywhere in the file caused subsequent insertions to be skipeed. PR #33393 addressed this but introduced a bug that would cause the insertbefore section to evaluate to True with an in appropriate index value, causing an index out of bounds error or inserting the line in a very inappropriate place in the file.

Skipping this section of the code when using BOF with insertbefore and postponing that until later resolves the issue.

Fixes #38219 (and hopefully some others)

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lineinfile.py

ANSIBLE VERSION
2.5
2.6
2.7

If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.
@ansibot
Copy link
Contributor

ansibot commented Jun 21, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Jun 21, 2018
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Jun 21, 2018
@samdoran samdoran merged commit eaae131 into ansible:devel Jun 25, 2018
@samdoran samdoran deleted the issue/38219-lineinfile-insertbefore-bof branch June 25, 2018 20:24
samdoran added a commit to samdoran/ansible that referenced this pull request Jun 25, 2018
If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.

(cherry picked from commit eaae131)
samdoran added a commit to samdoran/ansible that referenced this pull request Jun 25, 2018
If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.

(cherry picked from commit eaae131)
jacum pushed a commit to jacum/ansible that referenced this pull request Jun 26, 2018
If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.
mattclay pushed a commit that referenced this pull request Jun 26, 2018
…er in the module (#41929)

* Skip if insertbefore BOF until later (#41767)

If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.

(cherry picked from commit eaae131)

* Add changelog fragment
kbreit pushed a commit to kbreit/ansible that referenced this pull request Jul 3, 2018
…til later in the module (ansible#41929)

* Skip if insertbefore BOF until later (ansible#41767)

If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.

(cherry picked from commit eaae131)

* Add changelog fragment
nitzmahone pushed a commit that referenced this pull request Jul 3, 2018
…r in the module (#41930)

* Skip if insertbefore BOF until later (#41767)

If a line match is found in the file and no regexp is specified, insertbefore would improperly try to add a line if set to BOF.

Add tests for this scenario.

(cherry picked from commit eaae131)

* Add changelog fragment
@ansible ansible locked and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lineinfile not working with insertbefore: BOF in Ansible 2.5.0
4 participants