# Ini\_file deletes everything in the file that I did not specify

**URL:** <https://forum.ansible.com/t/ini-file-deletes-everything-in-the-file-that-i-did-not-specify/39891>\
**Category:** Get Help\
**Created:** [January 28, 2025, 6:11pm UTC](https://forum.ansible.com/t/ini-file-deletes-everything-in-the-file-that-i-did-not-specify/39891 "2025-01-28T18:11:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![markfaine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/markfaine/32/7291_2.png) [@markfaine](https://forum.ansible.com/u/markfaine)\
**Post date:** [January 28, 2025, 6:11pm UTC](https://forum.ansible.com/t/ini-file-deletes-everything-in-the-file-that-i-did-not-specify/39891/1 "2025-01-28T18:11:48Z")

</div>

I am simply trying to add a key=value to a specific section, however, ini\_file seems to remove everything that was in the file originally and replace it with my key=value in [section]. I can’t imagine anyone would want that behavior. Is there something I’m doing wrong? I’ve tried it with exclusive=true and without exclusive and the result is the same.

Original Version of the file:

```auto
#This unit file replaces the traditional start-up script for systemd
#configurations, and is used when enabling boot-start for Splunk on
#systemd-based Linux distributions.

[Unit]
Description=Systemd service file for Splunk, generated by 'splunk enable boot-start'
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
Restart=always
ExecStart=/opt/splunkforwarder/bin/splunk _internal_launch_under_systemd
KillMode=mixed
KillSignal=SIGINT
TimeoutStopSec=360
LimitNOFILE=65536
LimitRTPRIO=99
SuccessExitStatus=51 52
RestartPreventExitStatus=51
RestartForceExitStatus=52
User=splunkfwd
Group=splunkfwd
NoNewPrivileges=yes
PermissionsStartOnly=true
AmbientCapabilities=CAP_DAC_READ_SEARCH
ExecStartPre=-/bin/bash -c "chown -R splunkfwd:splunkfwd /opt/splunkforwarder"

[Install]
WantedBy=multi-user.target

```

My tasks:

```yml
  - name: Ensure "AmbientCapibilities is in section "[Service]" in the SplunkForwarder service config
    community.general.ini_file:
      path: /etc/systemd/system/SplunkForwarder.service
      section: Service
      option: AmbientCapabilities
      value: "{{ splunk_forwarder_ambient_capabilities | default(['CAP_DAC_READ_SEARCH']) | list | flatten | unique | join(' ') }}"
      mode: '0644'
      backup: true
      no_extra_spaces: true
      exclusive: true
    become: true

  - name: Add ExecStartPre in the "[Service]" section to set permissions on streamfwd file
    community.general.ini_file:
      path: /etc/systemd/system/SplunkForwarder.service
      section: Service
      option: ExecStartPre
      value: '-/bin/bash -c "chmod 4711 {{ splunk_forwarder_home }}/etc/apps/Splunk_TA_stream/linux_x86_64/bin/streamfwd"'
      mode: '0644'
      backup: true
      no_extra_spaces: true
    become: true

```

The resulting output:

```auto

[Service]
AmbientCapabilities=CAP_DAC_READ_SEARCH CAP_NET_RAW CAP_NET_ADMIN
ExecStartPre=-/bin/bash -c "chmod 4711 /opt/splunkforwarder/etc/apps/Splunk_TA_stream/linux_x86_64/bin/streamfwd"

```

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [January 28, 2025, 7:40pm UTC](https://forum.ansible.com/t/ini-file-deletes-everything-in-the-file-that-i-did-not-specify/39891/2 "2025-01-28T19:40:43Z")

</div>

Instead of starting a new thread for the exact same problem you should update your old one.

---

<div class="post-metadata">

**Author:** ![markfaine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/markfaine/32/7291_2.png) [@markfaine](https://forum.ansible.com/u/markfaine)\
**Post date:** [January 28, 2025, 8:12pm UTC](https://forum.ansible.com/t/ini-file-deletes-everything-in-the-file-that-i-did-not-specify/39891/3 "2025-01-28T20:12:48Z")

</div>

I guess I’m getting old. I don’t remember making an old one.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 27, 2025, 8:13pm UTC](https://forum.ansible.com/t/ini-file-deletes-everything-in-the-file-that-i-did-not-specify/39891/4 "2025-02-27T20:13:40Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
