Ansible - loop through multiple files when with_items defined

This is similar to another question I posed a few days ago, but different enough I thought it deserved its own topic. I have a variable of ifcfg-list.stdout_lines that contains a list of ifcfg-* file names (exlcuding loopback). I need to iterate the following code over this list (apply it to all ifcfg-* files), but don’t know how to do it. with_nested doesn’t seem to be the right solution to me. I know I can do this in multiple tasks (already done), but I am trying to consolidate all of the tasks down to a single task:

`

  • name: Gather list of ifcfg-* files
    shell: ls “{{ net_path }}” | grep ^ifcfg- | grep 0$ | grep -ve ifcfg-lo -e @ # @ excludes ansible backup files
    register: ifcfg_list
    changed_when: false

  • name: Update ifcfg-* files
    ini_file:
    path: “{{ net_path }}{{ ifcfg_list.stdout_lines }}” #<-- I know this is wrong, but I need to iterate through this list and apply the changes to all files.
    no_extra_spaces: true
    section: null
    state: present
    option: “{{ item.option }}”
    value: “{{ item.value }}”
    with_items:

  • { option: “NM_CONTROLLED”, value: “no” }

  • { option: “PEERDNS”, value: “no” }

  • { option: “DNS1”, value: “{{ dns1 }}” }

  • { option: “DNS2”, value: “{{ dns2 }}” }
    notify:

  • Networking

`

What's wrong with "with_nested"?

Nothing I guess, other than I didn’t know how to use it in this scenario. Thank you for your example, I will go and work with it.

Uwe Sauter,

It worked perfectly! Thank you.

You're welcome.