-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 file.comment ignore_missing #62045
Add file.comment ignore_missing #62045
Conversation
re-run pr-debian-11-arm64-py3-pytest |
re-run pr-freebsd-130-amd64-py3-pytest |
1 similar comment
re-run pr-freebsd-130-amd64-py3-pytest |
This PR has resulted in a regression, when the line matched by the provided Identified 764c769 as the offending commit using 764c7699eb98c9b5f4dac43b1b2cba17e4bce34c is the first bad commit
commit 764c7699eb98c9b5f4dac43b1b2cba17e4bce34c
...
...
fixes saltstack/salt#61662 fix file.comment reports changes in test mode
salt/states/file.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-) Here's a minimal reproducible example: regression_file_comment/init/file.managed:
file.managed:
- name: /tmp/regression_file_comment
- contents: |
port = 5432 # (change requires restart)
regression_file_comment/init/file.comment:
file.comment:
- name: /tmp/regression_file_comment
- regex: ^port\s*=.+
- require:
- file: regression_file_comment/init/file.managed See further details below that may be useful. Encountered these failures during this week's In this case, the default port = 5432 # (change requires restart) This line is supposed to be commented out if a (different) port has been provided in the config. {%- set db_port = salt['config.option']('postgres.port') %}
{%- if db_port %}
postgresql-conf-comment-port:
file.comment:
- name: {{ postgres.conf_dir }}/postgresql.conf
- regex: ^port\s*=.+
- require:
- file: postgresql-config-dir
{%- endif %} With the regression being: ID: postgresql-conf-comment-port
Function: file.comment
Name: /etc/postgresql/13/main/postgresql.conf
Result: False
Comment: port\s*=.+: Pattern not found |
What does this PR do?
This PR adds the ability to ignore missing regex matches in a file when using the
file.comment
state. This allows for a "comment only if a match is found" workflow and prevents unnecessary state failures or requisite use. This PR also fixes a small bug where changes would be reported in test mode when the line has already been commented.What issues does this PR fix or reference?
Fixes: #62044
Fixes: #61662
Previous Behavior
See relevant issues for details.
New Behavior
The
ignore_missing
parameter allows the state to succeed if the line to be commented is not found. Additionally, changes are no longer reported in test mode when the line is already commented.Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.