# file module, why useless src should be an error with state absent ?

**URL:** <https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592>\
**Category:** Ansible Project\
**Created:** [February 9, 2021, 10:17am UTC](https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592 "2021-02-09T10:17:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Caillibaud](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Caillibaud](https://forum.ansible.com/u/Daniel_Caillibaud)\
**Post date:** [February 9, 2021, 10:17am UTC](https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592/1 "2021-02-09T10:17:26Z")

</div>

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  
&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;path: "/etc/munin/plugins/{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;state: "{{ is\_baremetal | ternary('link', 'absent') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;src: "/usr/share/munin/plugins/{{ item }}"  
&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;- acpi  
&nbsp;&nbsp;&nbsp;&nbsp;- cpu  
&nbsp;&nbsp;&nbsp;&nbsp;- cpuspeed  
&nbsp;&nbsp;&nbsp;&nbsp;- diskstats  
&nbsp;&nbsp;&nbsp;&nbsp;- entropy  
&nbsp;&nbsp;&nbsp;&nbsp;- forks  
&nbsp;&nbsp;&nbsp;&nbsp;- fw\_packets  
&nbsp;&nbsp;&nbsp;&nbsp;- interrupts  
&nbsp;&nbsp;&nbsp;&nbsp;- irqstats  
&nbsp;&nbsp;&nbsp;&nbsp;- load  
&nbsp;&nbsp;&nbsp;&nbsp;- proc\_pri  
&nbsp;&nbsp;&nbsp;&nbsp;- swap  
&nbsp;&nbsp;&nbsp;&nbsp;- threads  
&nbsp;&nbsp;&nbsp;&nbsp;- vmstat  
&nbsp;&nbsp;notify: restart munin-node  
&nbsp;&nbsp;tags: ['config', 'munin-node']

It works, but it show this warning

&nbsp;&nbsp;[WARNING]: The src option requires state to be 'link' or 'hard'. This will become an error in  
&nbsp;&nbsp;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`)

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 9, 2021, 11:29am UTC](https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592/2 "2021-02-09T11:29:30Z")

</div>

Wouldn't help to link conditionally? e.g.

- name: enable plugins for baremetal only  
&nbsp;&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;when: is\_baremetal|bool  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: link  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: "/etc/munin/plugins/{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: "/usr/share/munin/plugins/{{ item }}"  
&nbsp;&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- acpi  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- cpu  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

---

<div class="post-metadata">

**Author:** ![Daniel\_Caillibaud](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Caillibaud](https://forum.ansible.com/u/Daniel_Caillibaud)\
**Post date:** [February 9, 2021, 11:47am UTC](https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592/3 "2021-02-09T11:47:39Z")

</div>

Yes, but instead of my uniq task I need to write the same thing twice

- name: enable plugins for baremetal only  
&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;state: link  
&nbsp;&nbsp;&nbsp;&nbsp;path: "/etc/munin/plugins/{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;src: "/usr/share/munin/plugins/{{ item }}"  
&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;- acpi  
&nbsp;&nbsp;&nbsp;&nbsp;- cpu  
&nbsp;&nbsp;when: is\_baremetal|bool

- name: disable same plugins for others  
&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;state: absent  
&nbsp;&nbsp;&nbsp;&nbsp;path: "/etc/munin/plugins/{{ item }}"  
&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;- acpi  
&nbsp;&nbsp;&nbsp;&nbsp;- cpu  
&nbsp;&nbsp;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 ?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 9, 2021, 12:21pm UTC](https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592/4 "2021-02-09T12:21:49Z")

</div>

It's possible to omit src conditionally e.g.

- name: enable plugins for baremetal only  
&nbsp;&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: "/etc/munin/plugins/{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: "{{ is\_baremetal | ternary('link', 'absent') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: "{{ is\_baremetal | ternary('/usr/share/munin/plugins/' ~ item, omit) }}"  
&nbsp;&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- acpi  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- cpu  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

(As a workaround, not very nice, ...). Your remark is valid. +1

---

<div class="post-metadata">

**Author:** ![Daniel\_Caillibaud](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Daniel\_Caillibaud](https://forum.ansible.com/u/Daniel_Caillibaud)\
**Post date:** [February 9, 2021, 7:32pm UTC](https://forum.ansible.com/t/file-module-why-useless-src-should-be-an-error-with-state-absent/34592/5 "2021-02-09T19:32:26Z")

</div>

Still nicer than duplicate all the task, thanks a lot !

(my "pb" is solved and I learnt something)
