using 2 loops with_first_found and with_items

353 views
Skip to first unread message

Hudec Peter

unread,
Jul 23, 2014, 12:24:52 AM7/23/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Jul 24, 2014, 7:46:56 PM7/24/14
to ansible...@googlegroups.com
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?

 



                Peter Hudec

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CFF505AC.3A5BF%25peter.hudec%40cnc.sk.
For more options, visit https://groups.google.com/d/optout.

Hudec Peter

unread,
Jul 28, 2014, 9:25:26 AM7/28/14
to ansible...@googlegroups.com
Hi Micheal,

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

Thanks
Peter

Michael DeHaan

unread,
Jul 28, 2014, 10:13:56 AM7/28/14
to ansible...@googlegroups.com
My suggestion is 2 lines in the playbook versus your 7.




Reply all
Reply to author
Forward
0 new messages