file src and state=absent together

Hi,

I like constructs like the following:

- name: MPM prefork
  file:
    src: "../../apache2/mods-available/{{ configfile }}"
    dest: "/etc/apache2{{ instance_dashsuffix }}/mods-enabled/{{ configfile }}"
    state: "{{ (instance.instance_data.mpm=='prefork') | ternary('link','absent') }}"
  loop_control:
    loop_var: "configfile"
  loop:
    - "mpm_prefork.load"
    - "mpm_prefork.conf"

A warning tells me that having state=absent and a source at the same time will
be an error in ansible 2.10

How would I write this in the future?

I do sincerely hope that I wouldn't be forced to write two tasks like:

- name: MPM prefork on
  file:
    src: "../../apache2/mods-available/{{ configfile }}"
    dest: "/etc/apache2{{ instance_dashsuffix }}/mods-enabled/{{ configfile }}"
    state: "link"
  when: "{{ (instance.instance_data.mpm=='prefork') }}"
  loop_control:
    loop_var: "configfile"
  loop:
    - "mpm_prefork.load"
    - "mpm_prefork.conf"

- name: MPM prefork on
  file:
    dest: "/etc/apache2{{ instance_dashsuffix }}/mods-enabled/{{ configfile }}"
    state: "absent"
  when: "{{ (instance.instance_data.mpm!='prefork') }}"
  loop_control:
    loop_var: "configfile"
  loop:
    - "mpm_prefork.load"
    - "mpm_prefork.conf"

causing a lot of duplication.

Greetings
Marc

You need to add ternary on src also and use the variable omit when false.
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#omitting-parameters

I must say, I don't understand why they are doing this change. It make us write
more code that IMHO makes the code more difficult to read.

You need to add ternary on src also and use the variable omit when false.
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#omitting-parameters

Of course. Thanks.

I must say, I don't understand why they are doing this change. It make us write
more code that IMHO makes the code more difficult to read.

I could not agree more.

Greetings
Marc