If your control node has Jinja2.7 you may be able to use the 'map'
filter to emulate the desired comprehension
See http://jinja.pocoo.org/docs/templates/#builtin-filters


Kahlil (Kal) Hodgson                       GPG: C9A02289
Head of Technology                         (m) +61 (0) 4 2573 0382
DealMax Pty Ltd                            (w) +61 (0) 3 9008 5281

Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia

"All parts should go together without forcing.  You must remember that
the parts you are reassembling were disassembled by you.  Therefore,
if you can't get them together again, there must be a reason.  By all
means, do not use a hammer."  -- IBM maintenance manual, 1925



On Tue, Jan 28, 2014 at 8:49 PM, Nick <[email protected]> wrote:
> Hi,
>
> When writing roles, I try and keep them re-usable.  This means avoiding
> making them dependent on any arrangement of vars in my inventory and
> playbooks.
>
> The problem I keep bumping into then is that ansible / jinja2 have limited
> means of transforming, for example, a list of server description hashes,
> into a hash of server name to ssh public keys.
>
> I find myself pining for list comprehensions, so I could do this sort of
> thing:
>
>   vars:
>     # an example of a typical datastructure in the inventory:
>     # details aren't important, what matters is that it is not
>     # 1:1 with the role's requirements
>     servers:
>       - name: server1
>         ssh:
>           keys:
>             rsa:
>               pub: 'xsdfjhdkfuhwef ...'
>               prv: '...'
>         # ...
>       - name: server2
>         ssh:
>         # ... and so on
>
>   # elsewhere...
>   roles:
>     # This role just wants a dictionary mapping server name -> rsa public
> key
>     - role: foo
>       server_keys: <list comprehension here>
>
> ...Where the list comprehension creates a map of item.name ->
> item.ssh.keys.rsa.pub extracted from the 'servers' list.
>
> How do other people approach this?  Is there a good solution?
>
> Thanks,
>
> N
>
> --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to