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

fix: greedy match may cause unwanted replacement #58960

Closed
wants to merge 1 commit into from

Conversation

centurycoder
Copy link

@centurycoder centurycoder commented Jul 11, 2019

SUMMARY

say we have below 2 existing blocks in file, and we specify "marker_begin_text_1" in playbook to do an update.
But because of greedy match, the content of block 2 will also be overwritten.
So this pull request is to resolve this issue.

marker_begin_text_1
content1
end
marker_begin_text_2
content2
end

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

files/blockinfile.py

ADDITIONAL INFORMATION

say we have below 2 existing blocks in file, and we specify "marker_begin_text_1" in playbook to do an update.
But because of greedy match, the content of block 2 will also be overwritten.
So this pull request is to resolve this issue.


marker_begin_text_1
    content1
end
marker_begin_text_2
    content2
end
@ansibot
Copy link
Contributor

ansibot commented Jul 11, 2019

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. files Files category module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jul 11, 2019
@ansibot
Copy link
Contributor

ansibot commented Jul 11, 2019

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/modules/files/blockinfile.py:285:16: singleton-comparison Comparison to None should be 'expr is not None'

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

lib/ansible/modules/files/blockinfile.py:285:20: E711 comparison to None should be 'if cond is not None:'
lib/ansible/modules/files/blockinfile.py:286:15: E111 indentation is not a multiple of four

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jul 11, 2019
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Jul 11, 2019
@@ -282,6 +282,8 @@ def main():
n0 = i
if line == marker1:
n1 = i
if (n0 != None):
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not change current behaviour, add an option that defaults to the current greedy=yes|no

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not change current behaviour, add an option that defaults to the current greedy=yes|no

@bcoca
That would be wonderful to have such an option. Thank you for your adoption.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jul 20, 2019
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 16, 2020
@ansibot ansibot added pre_azp This PR was last tested before migration to Azure Pipelines. and removed ci_verified Changes made in this PR are causing tests to fail. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Dec 5, 2020
@bcoca
Copy link
Member

bcoca commented Jan 12, 2022

closing as per above

@bcoca bcoca closed this Jan 12, 2022
@ansible ansible locked and limited conversation to collaborators Jan 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. pre_azp This PR was last tested before migration to Azure Pipelines. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants