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

ini_file: Don't creates new file instead of following symlink #6546

Merged
merged 3 commits into from
May 29, 2023

Conversation

goneri
Copy link
Member

@goneri goneri commented May 20, 2023

SUMMARY

This is a bug fix that address a situation where community.general.ini_file was destroying symlinks instead of updating of updating their targets.

If poth points on a symlink and follow is true, the ini_file plugin will preserve the symlink and modify the target file.

Closes: #6470

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ini_file

This is a bug fix that address a situation where `community.general.ini_file`
was destroying symlinks instead of updating of updating their targets.

Closes: ansible-collections#6470
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug integration tests/integration module module plugins plugin (any type) tests tests labels May 20, 2023
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I'm wondering whether changing the behavior is a good idea, since some folks might rely on it. I think it might be better to make this behavior configurable, by adding a follow option (similar to https://docs.ansible.com/ansible/devel/collections/ansible/builtin/copy_module.html#parameter-follow).

@@ -0,0 +1,3 @@
---
bugfixes:
- "ini_file - Follow the symlinks instead of replacing them (https://github.com/ansible-collections/community.general/issues/6470)."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- "ini_file - Follow the symlinks instead of replacing them (https://github.com/ansible-collections/community.general/issues/6470)."
- "ini_file - follow the symlinks instead of replacing them (https://github.com/ansible-collections/community.general/issues/6470, https://github.com/ansible-collections/community.general/pull/6546)."

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-7 labels May 20, 2023
@goneri
Copy link
Member Author

goneri commented May 20, 2023

Hi @felixfontein!

From my view point, this was more an unpredictable bug. But I understand your point of view. This is a bit of a XKCD 1172: Workflow situation (https://www.explainxkcd.com/wiki/index.php/1172:_Workflow). I'm a bit hesitant to add a key just for the users who were relying on the previous behaviour. Would you be fine with an entry in the documentation that cover the symlink case?

@felixfontein
Copy link
Collaborator

@goneri I see the current behavior as somewhat surprising (since most modules don't act the same), but it does have a certain consistency. I can imagine some use-cases where the current behavior is explicitly needed and changing it would be a bug.

So from this POV this is a breaking change and cannot happen without a longer deprecation period. In any case, before it's decided whether the default behavior should change, it makes sense to make the behavior configurable, since both behaviors make sense for specific use-cases.

@goneri
Copy link
Member Author

goneri commented May 21, 2023

Agreed.

If `poth` points on a symlink and `follow` is true, the `ini_file` plugin
will preserve the symlink and modify the target file.
@goneri goneri requested a review from felixfontein May 22, 2023 14:29
plugins/modules/ini_file.py Outdated Show resolved Hide resolved
plugins/modules/ini_file.py Outdated Show resolved Hide resolved
plugins/modules/ini_file.py Outdated Show resolved Hide resolved
- yes/no -> true/false.
- new key will be introduced in 7.1.0.
- clean up the `state=link` part.
@ansibullbot ansibullbot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels May 24, 2023
@goneri goneri requested a review from felixfontein May 24, 2023 14:45
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Looks good to me. I will merge for 7.1.0 if nobody objects.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label May 29, 2023
@felixfontein felixfontein merged commit c76af60 into ansible-collections:main May 29, 2023
@patchback
Copy link

patchback bot commented May 29, 2023

Backport to stable-7: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-7/c76af60a73c9c058524313cf912a0e08e8427975/pr-6546

Backported as #6598

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator

@goneri thanks for your contribution!

patchback bot pushed a commit that referenced this pull request May 29, 2023
* ini_file: Don't creates new file instead of following symlink

This is a bug fix that address a situation where `community.general.ini_file`
was destroying symlinks instead of updating of updating their targets.

Closes: #6470

* ini_file: add the follow parameter

If `poth` points on a symlink and `follow` is true, the `ini_file` plugin
will preserve the symlink and modify the target file.

* adjust the documentation of the new key

- yes/no -> true/false.
- new key will be introduced in 7.1.0.
- clean up the `state=link` part.

(cherry picked from commit c76af60)
felixfontein pushed a commit that referenced this pull request May 29, 2023
…le instead of following symlink (#6598)

ini_file: Don't creates new file instead of following symlink (#6546)

* ini_file: Don't creates new file instead of following symlink

This is a bug fix that address a situation where `community.general.ini_file`
was destroying symlinks instead of updating of updating their targets.

Closes: #6470

* ini_file: add the follow parameter

If `poth` points on a symlink and `follow` is true, the `ini_file` plugin
will preserve the symlink and modify the target file.

* adjust the documentation of the new key

- yes/no -> true/false.
- new key will be introduced in 7.1.0.
- clean up the `state=link` part.

(cherry picked from commit c76af60)

Co-authored-by: Gonéri Le Bouder <[email protected]>
jikamens added a commit to jikamens/community.general that referenced this pull request Sep 16, 2023
It appears that ansible-collections#6546 added symlink tests but neglected to add them to
main.yml so they weren't being executed.
felixfontein pushed a commit that referenced this pull request Sep 17, 2023
…7273)

* Add `ignore_spaces` option to `ini_file` to ignore spacing changes

Add a new `ignore_spaces` option to the `ini_file` module which, if
true, prevents the module from changing a line in a file if the only
thing that would change by doing so is whitespace before or after the
`=`.

Also add test cases for this new functionality. There were previously
no tests for `ini_file` at all, and this doesn't attempt to fix that,
but it does add tests to ensure that the new behavior implemented here
as well as the old behavior in the affected code are correct.

Fixes #7202.

* Add changelog fragment

* pep8 / pylint

* remove unused import

* fix typo in comment in integration test file

* Add symlink tests to main.yml

It appears that #6546 added symlink tests but neglected to add them to
main.yml so they weren't being executed.

* ini_file symlink tests; create output files in correct location

* Add integration tests for ini_file ignore_spaces

* PR feedback
patchback bot pushed a commit that referenced this pull request Sep 17, 2023
…7273)

* Add `ignore_spaces` option to `ini_file` to ignore spacing changes

Add a new `ignore_spaces` option to the `ini_file` module which, if
true, prevents the module from changing a line in a file if the only
thing that would change by doing so is whitespace before or after the
`=`.

Also add test cases for this new functionality. There were previously
no tests for `ini_file` at all, and this doesn't attempt to fix that,
but it does add tests to ensure that the new behavior implemented here
as well as the old behavior in the affected code are correct.

Fixes #7202.

* Add changelog fragment

* pep8 / pylint

* remove unused import

* fix typo in comment in integration test file

* Add symlink tests to main.yml

It appears that #6546 added symlink tests but neglected to add them to
main.yml so they weren't being executed.

* ini_file symlink tests; create output files in correct location

* Add integration tests for ini_file ignore_spaces

* PR feedback

(cherry picked from commit 8a9b982)
felixfontein pushed a commit that referenced this pull request Sep 17, 2023
…`ini_file` to ignore spacing changes (#7279)

Add `ignore_spaces` option to `ini_file` to ignore spacing changes (#7273)

* Add `ignore_spaces` option to `ini_file` to ignore spacing changes

Add a new `ignore_spaces` option to the `ini_file` module which, if
true, prevents the module from changing a line in a file if the only
thing that would change by doing so is whitespace before or after the
`=`.

Also add test cases for this new functionality. There were previously
no tests for `ini_file` at all, and this doesn't attempt to fix that,
but it does add tests to ensure that the new behavior implemented here
as well as the old behavior in the affected code are correct.

Fixes #7202.

* Add changelog fragment

* pep8 / pylint

* remove unused import

* fix typo in comment in integration test file

* Add symlink tests to main.yml

It appears that #6546 added symlink tests but neglected to add them to
main.yml so they weren't being executed.

* ini_file symlink tests; create output files in correct location

* Add integration tests for ini_file ignore_spaces

* PR feedback

(cherry picked from commit 8a9b982)

Co-authored-by: Jonathan Kamens <[email protected]>
etrombly pushed a commit to etrombly/community.general that referenced this pull request Oct 25, 2023
…nsible-collections#7273)

* Add `ignore_spaces` option to `ini_file` to ignore spacing changes

Add a new `ignore_spaces` option to the `ini_file` module which, if
true, prevents the module from changing a line in a file if the only
thing that would change by doing so is whitespace before or after the
`=`.

Also add test cases for this new functionality. There were previously
no tests for `ini_file` at all, and this doesn't attempt to fix that,
but it does add tests to ensure that the new behavior implemented here
as well as the old behavior in the affected code are correct.

Fixes ansible-collections#7202.

* Add changelog fragment

* pep8 / pylint

* remove unused import

* fix typo in comment in integration test file

* Add symlink tests to main.yml

It appears that ansible-collections#6546 added symlink tests but neglected to add them to
main.yml so they weren't being executed.

* ini_file symlink tests; create output files in correct location

* Add integration tests for ini_file ignore_spaces

* PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug integration tests/integration module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ini_file creates new file instead of following symlink
3 participants