using 2 loops with_first_found and with_items

Hi,

I’m trying to write role for configuration of the package management. In
this role I following setup.

— defaults/main.yml
debain_source_list:
  - name: debian
  state: enabled
- name: debian-backports
  state: enabled
- name: debian-lts
  state: enabled

— task/setup-Debian.yml
- name: "[repository] apt source list files"
  action: template src=??? dest=/etc/apt/sources.d/???.list
  with_items: " {{ debain_source_list }}"
  when: "item.state != 'enabled'"
  with_first_found:
  - {{ item.name }}.list.{{ ansible_lsb.id }}.{{ ansible_lsb.codename }}
  - default.list

The idea is to have separate source list files for each Debian release
/wheeze, squeeze, …/, if the file is not found put there some default
file. The problem is how to run more loops and address variables in one
action.

Consider this to be an example and will be used as template for another
actions. I do not want to sync the directories.

  Best regards
    Peter Hudec

Can’t combine these two things.

Also, when using with_foo: var, don’t use jinja2.

Not like:

with_items: “{{ foo }}”

Do it like so:

with_items: alist_variable

I’d just have a bunch of templates like so:

  • template: src={{ item}} dest=/etc/apt/sources.list.d/{{ item.basename }}
    with_fileglob: ‘*.sources.j2’

You may need to reference a hash that keys off of something like “{{ item | basename }}” inside your template, such as

{# set basename = item|basename #}
{{ repo_url[basename] }}

etc

Sort of make sense?

Hi Micheal,

I will try your approach but I found it no so pretty as suggested :slight_smile:

Thanks
Peter

My suggestion is 2 lines in the playbook versus your 7.