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

Add warning when using an empty regexp in lineinfile #42013

Merged
merged 9 commits into from
Jun 30, 2018

Conversation

samdoran
Copy link
Contributor

SUMMARY

Reverts #41451 and adds a warning instead.

See #29443 for reasoning behind this change.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lineinfile.py

ANSIBLE VERSION
2.7

@samdoran samdoran requested review from abadger and bcoca June 27, 2018 16:00
@ansibot
Copy link
Contributor

ansibot commented Jun 27, 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 27, 2018
@@ -480,12 +480,17 @@ def main():
regexp = params['regexp']
line = params.get('line', None)

if regexp == '':
module.warn(
'The regular expression is empty, which will match every line in the file.'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to say "empty string". We also may want to give an alternative for people who actually do want to match every line in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "give an alternative"? This warning could be annoying to someone who does want this capability, and I don't want to encourage folks to disable warnings with noisy error messages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Give an example of a regex to use if they really want to match every line. (I think "^" would do it and be efficient). We could also give an example of unsetting it but that isn't as succinctly written.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that's perfect! I see what you're saying.

@@ -717,37 +717,3 @@
assert:
that:
- result.stat.checksum == 'eca8d8ea089d4ea57a3b87d4091599ca8b60dfd2'
Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping tests (but updating if the results have changed) seems like a good idea. Then it's an additional clue that the behaviour was meant to be this way.

@abadger
Copy link
Contributor

abadger commented Jun 27, 2018

Also, I think we want a changelog for this? (And maybe a porting guide?)

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jun 27, 2018
@samdoran samdoran force-pushed the issue/29443/empty-string-regexp-v2 branch from 5cd76fe to 66e41e5 Compare June 27, 2018 16:32
Offer an equivalent regexp that won't trigger the warning.
Update tests to match new warning.
@ansibot ansibot added the docs This issue/PR relates to or includes documentation. label Jun 28, 2018
@abadger abadger merged commit fb55038 into ansible:devel Jun 30, 2018
@samdoran samdoran deleted the issue/29443/empty-string-regexp-v2 branch July 2, 2018 16:19
samdoran added a commit to samdoran/ansible that referenced this pull request Jul 2, 2018
* Revert "Account for empty string regexp in lineinfile (ansible#41451)"

This reverts commit 4b5b4a7.

* Use context managers for interacting with files

* Store line and regexp parameters in a variable

* Add warning when regexp is an empty string

* Remove '=' from error messages

* Update warning message and add changelog

* Add tests

* Improve warning message

Offer an equivalent regexp that won't trigger the warning.
Update tests to match new warning.

* Add porting guide entry for lineinfile change

# Conflicts:
#	docs/docsite/rst/porting_guides/porting_guide_2.7.rst
#	lib/ansible/modules/files/lineinfile.py
#	test/integration/targets/lineinfile/tasks/main.yml
samdoran added a commit to samdoran/ansible that referenced this pull request Jul 3, 2018
* Revert "Account for empty string regexp in lineinfile (ansible#41451)"

This reverts commit 4b5b4a7.

* Use context managers for interacting with files

* Store line and regexp parameters in a variable

* Add warning when regexp is an empty string

* Remove '=' from error messages

* Update warning message and add changelog

* Add tests

* Improve warning message

Offer an equivalent regexp that won't trigger the warning.
Update tests to match new warning.

* Add porting guide entry for lineinfile change

(cherry picked from commit fb55038)
nitzmahone pushed a commit that referenced this pull request Jul 5, 2018
* Revert "Account for empty string regexp in lineinfile (#41451)"

This reverts commit 4b5b4a7.

* Use context managers for interacting with files

* Store line and regexp parameters in a variable

* Add warning when regexp is an empty string

* Remove '=' from error messages

* Update warning message and add changelog

* Add tests

* Improve warning message

Offer an equivalent regexp that won't trigger the warning.
Update tests to match new warning.

* Add porting guide entry for lineinfile change

(cherry picked from commit fb55038)
mattclay pushed a commit that referenced this pull request Jul 9, 2018
* Add warning when using an empty regexp in lineinfile (#42013)

* Revert "Account for empty string regexp in lineinfile (#41451)"

This reverts commit 4b5b4a7.

* Use context managers for interacting with files

* Store line and regexp parameters in a variable

* Add warning when regexp is an empty string

* Remove '=' from error messages

* Update warning message and add changelog

* Add tests

* Improve warning message

Offer an equivalent regexp that won't trigger the warning.
Update tests to match new warning.

* Add porting guide entry for lineinfile change

# Conflicts:
#	docs/docsite/rst/porting_guides/porting_guide_2.7.rst
#	lib/ansible/modules/files/lineinfile.py
#	test/integration/targets/lineinfile/tasks/main.yml

* Add porting guide info
@ansible ansible locked and limited conversation to collaborators Jul 1, 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. docs This issue/PR relates to or includes documentation. 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.

None yet

4 participants