How to loop over ansible_mounts[elements].mount

Dear friends

I need to generate a line in a configuration file based on ansible_mounts but only when /home mount is present.

I know for instance that I can access ansible_mounts[1].mount or ansible_mounts[2].mount but not even ansible_mounts[1].mount nor ansible_mounts[2].mount are /home.

My idea is to loop over ansible_mounts[elements].mount and check whether /home is present but what is not clear to me is how to loop when the numer of elements to loop over is not known in advance.

Kind regards.

Try something like this: - modulename: … when: item.mount == ‘/home’ with_items: ansible_mounts

quick example:

- hosts: localhost
  connection: local
  tasks:
    - debug: msg={{item.mount}}
      with_items: ansible_mounts
      when: item.mount == '/home'

Exactly what I want! Thanks :slight_smile: