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 creates new file instead of following symlink #6470

Closed
1 task done
tod-uma opened this issue May 1, 2023 · 3 comments · Fixed by #6546
Closed
1 task done

ini_file creates new file instead of following symlink #6470

tod-uma opened this issue May 1, 2023 · 3 comments · Fixed by #6546
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type)

Comments

@tod-uma
Copy link

tod-uma commented May 1, 2023

Summary

When you use community.general.ini_file to modify a symlink (like /etc/yum.conf which is a symlink to /etc/dnf/dnf.conf on a oel9 machine) it appears to copy the file, edit it and replace the symlink with the edited file. There should at least be an option to follow symlinks instead of replacing them.

Issue Type

Bug Report

Component Name

ini_file

Ansible Version

$ ansible --version
ansible [core 2.14.4]
  config file = /home/tod.detre/code/gitlab/tower-projects/ansible.cfg
  configured module search path = ['/home/tod.detre/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tod.detre/.virtualenvs/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = /home/tod.detre/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/tod.detre/.virtualenvs/ansible/bin/ansible
  python version = 3.9.14 (main, Jan  9 2023, 00:00:00) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2.1.0.1)] (/home/tod.detre/.virtualenvs/ansible/bin/python)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 6.5.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

OracleLinux 9

Steps to Reproduce

- name: "Ensure yum is configured to use a proxy (globally)"
  community.general.ini_file:
    path: "/etc/yum.conf"
    section: main
    option: proxy
    value: 'http://proxy.myorg.org:3128'

Expected Results

I expected it to edit the file that already existed instead of creating a new one.

Actual Results

Instead of modifying the existing file, it created a new file and replaced the symlink with it.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) labels May 1, 2023
goneri added a commit to goneri/community.general that referenced this issue May 20, 2023
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
@goneri
Copy link
Member

goneri commented May 20, 2023

Hi @tod-uma,

Thank you for reporting this. I just pushed a PR that address the problem. Can you give it a try.

patchback bot pushed a commit that referenced this issue 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 issue 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]>
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 has_pr module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants