I’m trying to use the ini_file
module to add AmbientCapabilties
option with three values to a file. It’s worse than just not idempotent, it’s destructive. The first time it works fine but the second time it removes everything else in the file except the section, option and values.
- 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 | list | flatten | unique | join(' ') }}"
mode: '0644'
backup: true
exclusive: true
no_extra_spaces: true
become: true
when: splunk_forwarder_ambient_capabilities is defined and splunk_forwarder_ambient_capabilities | length
I’ve tried doing it with values: {{ splunk_forwarder_ambient_capabilities }}
and section_has_values
but it seems this results in three individual option/value lines in the target file, like this:
AmbientCapabilities=foo
AmbientCapabilities=bar
AmbientCapabilities=baz
I can’t use a template because the service file is created by a command task that runs earlier in the role and can’t be easily replaced. I may be able to use lineinfile or some other module but I’d rather use ini_file because it matches the type of file (technically a systemd service file) but the structure is the same as an ini file.
I’m aware of systemd drop-ins but in this case the vendor has chosen to do things in a non-standard way so I have to work with what I have.