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

added number of matches to replace parameter #79094

Closed
wants to merge 2 commits into from

Conversation

shivamdurgbuns
Copy link
Contributor

Signed-off-by: Shivam Durgbuns shivamdurgbuns@gmail.com

SUMMARY

Added numberofmatches parameter to replace functionality to replace the first n number of matches during a replace function, the default is set to 0 i.e all the occurrences will be replaced.

Fixes: #78866

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

replace

Signed-off-by: Shivam Durgbuns <shivamdurgbuns@gmail.com>
@ansibot ansibot added affects_2.15 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Oct 10, 2022
@ansibot

This comment was marked as outdated.

@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. labels Oct 10, 2022
Signed-off-by: Shivam Durgbuns <shivamdurgbuns@gmail.com>
@ansibot ansibot removed 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. labels Oct 10, 2022
Copy link
Member

@bcoca bcoca left a comment

Choose a reason for hiding this comment

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

code lgtm, could you add a couple of integration tests to ensure we do not regress?

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Oct 11, 2022
@shivamdurgbuns
Copy link
Contributor Author

code lgtm, could you add a couple of integration tests to ensure we do not regress?

Sure will do that @bcoca

@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Oct 11, 2022
@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 Oct 23, 2022
@@ -0,0 +1,2 @@
minor_changes:
- added new `numberofmatches` paramter to replace function to replace the first n number of occurances (https://github.com/ansible/ansible/issues/78866)
Copy link
Contributor

Choose a reason for hiding this comment

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

after: "<Location /2>"
regexp: 'Require\s+[^\n]+$'
replace: 'Require ip {{ ips | join(" ") }}'
numberofmatches: 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using count to reflect the actual keyword parameter that you are using.

@zedr
Copy link
Contributor

zedr commented Nov 25, 2022

@shivamdurgbuns consider adding these tests:

  • Integration: Test the exact case that was mentioned in the feature request: Support firstmatch in ansible.builtin.replace #78866 (comment)
  • Unit: Test that the module behaves exactly the same in these two cases: 1) omitting the numberofmatches parameter and 2) providing the default value.
  • Unit: Test that the intended result is achieved when numberofmatches is given a value different that the default.

@s-hertel
Copy link
Contributor

Closing for inactivity

@s-hertel s-hertel closed this May 24, 2023
@ansible ansible locked and limited conversation to collaborators May 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.15 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support firstmatch in ansible.builtin.replace
6 participants