Hi,
I want a symlink to be present on some hosts and absent for others, so I write this task
- name: enable plugins for baremetal only
file:
path: "/etc/munin/plugins/{{ item }}"
state: "{{ is_baremetal | ternary('link', 'absent') }}"
src: "/usr/share/munin/plugins/{{ item }}"
loop:
- acpi
- cpu
- cpuspeed
- diskstats
- entropy
- forks
- fw_packets
- interrupts
- irqstats
- load
- proc_pri
- swap
- threads
- vmstat
notify: restart munin-node
tags: [ 'config', 'munin-node' ]
It works, but it show this warning
[WARNING]: The src option requires state to be 'link' or 'hard'. This will become an error in
Ansible 2.10
Why turn this to an error ?
It will force me to write almost the same task twice (one with `state: link` and a second
with `state: absent`)
vbotka
(Vladimir Botka)
2
Wouldn't help to link conditionally? e.g.
- name: enable plugins for baremetal only
file:
when: is_baremetal|bool
state: link
path: "/etc/munin/plugins/{{ item }}"
src: "/usr/share/munin/plugins/{{ item }}"
loop:
- acpi
- cpu
...
Yes, but instead of my uniq task I need to write the same thing twice
- name: enable plugins for baremetal only
file:
state: link
path: "/etc/munin/plugins/{{ item }}"
src: "/usr/share/munin/plugins/{{ item }}"
loop:
- acpi
- cpu
when: is_baremetal|bool
- name: disable same plugins for others
file:
state: absent
path: "/etc/munin/plugins/{{ item }}"
loop:
- acpi
- cpu
when: not is_baremetal
And to avoid inconsistency between these two task, a var or set_fact task need to be added (to
guarantee the same list in both task).
Much more complicated than a ternary in state prop of a uniq task…
It's just a remark, why forbid such a way to switch state link|absent ?
vbotka
(Vladimir Botka)
4
It's possible to omit src conditionally e.g.
- name: enable plugins for baremetal only
file:
path: "/etc/munin/plugins/{{ item }}"
state: "{{ is_baremetal | ternary('link', 'absent') }}"
src: "{{ is_baremetal | ternary('/usr/share/munin/plugins/' ~ item, omit) }}"
loop:
- acpi
- cpu
...
(As a workaround, not very nice, ...). Your remark is valid. +1
Still nicer than duplicate all the task, thanks a lot !
(my "pb" is solved and I learnt something)