Nested looping with dict/sub-list

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:

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.

That's an interesting strategy for getting the sources.list.d configured, but it relies on the fact that that line defining a deb repository can take multiple components 'deb http://mirrors.us.kernel.org/ubuntu/ precise main universe', so I'm no clearer on the real question about iterating over a dict with a sub-list.

  (although it also made me notice that I want to sort the dict and it's not immediately obvious how to do so: "with_dict: apt_repositories | dictsort" doesn't work - I think because dictsort yields a list of key,value pairs not a real dict).

Thanks for the helpful reply!

Duncan Hutty