ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
839 stars 1.54k forks source link

community.general.ini_file: allow_no_value is not plausible #6173

Open staehler opened 1 year ago

staehler commented 1 year ago

Summary

  - name: set options in ini file
    community.general.ini_file:
      path: "/tmp/test.ini"
      section: "test"
      option: "active"
      value: "true"
      #allow_no_value: true
      create: false
      state: present
      mode: 0640
      exclusive: true

When exlusive: true is set, allow_no_value:true shows weird behaviour.

I would expect, that exclusive: true takes care, that the regarding option is only once in a section.

Issue Type

Bug Report

Component Name

community.general.ini_file

Ansible Version

$ ansible --version
ansible [core 2.12.10]
  config file = /home/ttt/ansible.cfg
  configured module search path = ['/home/ttt/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ttt/ansible5.10.0/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/ttt/collections
  executable location = /home/ttt/ansible5.10.0/bin/ansible
  python version = 3.8.13 (default, Jun 14 2022, 17:49:07) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /home/ttt/ansible5.10.0/lib64/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.8.3  

# /home/ttt/ansible5.10.0/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.8.3  

# /home/ttt/collections/ansible_collections
Collection        Version
----------------- -------
community.general 6.4.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

RHEL 8

Steps to Reproduce

---

- name: test playbook
  hosts: localhost
  become: true

  tasks:
  - name: set options in splunk conf files (splunkOptionsOverwrite.yml)
    community.general.ini_file:
      path: "/tmp/test.ini"
      section: "test"
      option: "active"
      value: "true"
      allow_no_value: true
      create: false
      state: present
      mode: 0640
      exclusive: true

Have a /tmp/test.ini like

[test]
active = false

run the playbook and you will find in /tmp/test.ini the line active = true added, despite of exclusiv: true

[test]
active = false                                                                                                 
active = true

Expected Results

Only one line with the option active = true should be in the file.

Actual Results

see above

Code of Conduct

ansibullbot commented 1 year ago

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 commented 1 year ago

cc @jpmens @noseka1 click here for bot help