mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
[PR #6546/c76af60a backport][stable-7] ini_file: Don't creates new file 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 c76af60a73
)
Co-authored-by: Gonéri Le Bouder <goneri@lebouder.net>
This commit is contained in:
parent
5cec31586f
commit
c4ebd482eb
3 changed files with 86 additions and 10 deletions
|
@ -0,0 +1,59 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- block: &prepare
|
||||
- name: Create the final file
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
[main]
|
||||
foo=BAR
|
||||
dest: my_original_file.ini
|
||||
- name: Clean up symlink.ini
|
||||
ansible.builtin.file:
|
||||
path: symlink.ini
|
||||
state: absent
|
||||
- name: Create a symbolic link
|
||||
ansible.builtin.file:
|
||||
src: my_original_file.ini
|
||||
dest: symlink.ini
|
||||
state: link
|
||||
|
||||
- name: Set the proxy key on the symlink which will be converted as a file
|
||||
community.general.ini_file:
|
||||
path: symlink.ini
|
||||
section: main
|
||||
option: proxy
|
||||
value: 'http://proxy.myorg.org:3128'
|
||||
- name: Set the proxy key on the final file that is still unchanged
|
||||
community.general.ini_file:
|
||||
path: my_original_file.ini
|
||||
section: main
|
||||
option: proxy
|
||||
value: 'http://proxy.myorg.org:3128'
|
||||
register: result
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
# With follow
|
||||
- block: *prepare
|
||||
- name: Set the proxy key on the symlink which will be preserved
|
||||
community.general.ini_file:
|
||||
path: symlink.ini
|
||||
section: main
|
||||
option: proxy
|
||||
value: 'http://proxy.myorg.org:3128'
|
||||
follow: true
|
||||
register: result
|
||||
- name: Set the proxy key on the target directly that was changed in the previous step
|
||||
community.general.ini_file:
|
||||
path: my_original_file.ini
|
||||
section: main
|
||||
option: proxy
|
||||
value: 'http://proxy.myorg.org:3128'
|
||||
register: result
|
||||
- ansible.builtin.assert:
|
||||
that:
|
||||
- "not (result is changed)"
|
Loading…
Add table
Add a link
Reference in a new issue