I'm guessing what you want is:
apt_repository: repo="deb {{item.value.uri}} {{
ansible_distribution_release }}{{ item.value.suffix }} {{
item.components|join(" ") }}" state=present
This just uses the 'join' filter to join that components list into a space
separated string.
On Thu, Feb 5, 2015 at 9:07 AM, Duncan Hutty <[email protected]> wrote:
> I'm having a bit of difficulty with getting the behaviour that I want in
> as concise a way as I think should be possible.
>
> Here's the point:
> I'm having trouble with iterating over a hash where the value for one of
> the keys is itself a list. Is this possible with Ansible? Or would I need
> to write a custom iterator?
>
> I think that, having read the docs on how Ansible does looping (
> http://docs.ansible.com/playbooks_loops.html) that I must be
> misunderstanding something, so I'm asking for illumination concerning the
> general case - this repository problem is just an example.
>
>
> I want to configure /etc/apt/sources.list to contain:
>
> deb http://mirrors.us.kernel.org/ubuntu/ precise main
> deb http://mirrors.us.kernel.org/ubuntu/ precise universe
> deb http://mirrors.us.kernel.org/ubuntu/ precise-updates main
> deb http://mirrors.us.kernel.org/ubuntu/ precise-updates universe
> deb http://mirrors.us.kernel.org/ubuntu/ precise-security main
> deb http://mirrors.us.kernel.org/ubuntu/ precise-security universe
>
> My desired approach is to have a role called 'repositories', because I
> will need to take care of multiple platform versions/releases and
> non-distro/vendor repositories.
>
> roles/repositories/defaults/main.yml:
> ---
> # defaults file for repositories
> apt_repositories:
> vendor_base:
> uri: "http://mirrors.us.kernel.org/ubuntu/"
> suffix: ""
> components:
> - main
> - universe
> vendor_security:
> uri: "http://mirrors.us.kernel.org/ubuntu/"
> suffix: "-security"
> components:
> - main
> - universe
> vendor_updates:
> uri: "http://mirrors.us.kernel.org/ubuntu/"
> suffix: "-updates"
> components:
> - main
> - universe
>
>
> roles/repositories/tasks/main.yml
> ---
> # tasks file for apt repository config
> - name: "install standard apt repositories"
> apt_repository: repo="deb {{item.value.uri}} {{
> ansible_distribution_release }}{{ item.value.suffix }}" state=present
> with_dict: apt_repositories
>
>
> With the task as above, I get:
>
> deb http://mirrors.us.kernel.org/ubuntu/ precise
> deb http://mirrors.us.kernel.org/ubuntu/ precise-updates
> deb http://mirrors.us.kernel.org/ubuntu/ precise-security
>
> which is nearly there, but is missing the iteration over the list that is
> the subelement 'components'. I have attempted to use 'with_subelements' and
> I think perhaps I just haven't managed the correct incantation because I
> see in the debug output that the 'item' dict _does_ contain my components
> list.
>
> I've already managed to solve the immediate problem of getting the desired
> repos configured on my machines by using 'with_nested' with hard-coded
> _lists_ of suffixes and components and I realise that I could iterate over
> my entire dict with sublist data structure with a jinja2 template (instead
> of using the apt_repository module), but I'm posting for the general theory
> of iteration.
>
> Thank you for reading this far,
> Duncan Hutty
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/54D3874A.1050302%40allgoodbits.org.
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v8H-6PMqqzXnvtMdSf%3D6_zrzregbvekHR%3DHpWBXhAa8zQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.