Using an outer list to access an inner list with with_nested

27 views
Skip to first unread message

Ross Becker

unread,
Dec 18, 2014, 5:07:22 PM12/18/14
to ansible...@googlegroups.com
So, I tried to do this, and found it didn't work.  I wasn't terribly surprised, but it seems like a reasonable use-case.

The play is to be run on one host- a central server, and I have a list of groups that I want to perform actions for- for each host in each group.

The code looks something like this:

  1.   vars:
  2.     group_list: [ 'group1', 'group2', 'group3' ]
  3.     my_script: /some/script/foo.sh
  4.  
  5.   tasks:
  6.     - name: Nested task
  7.       command: ${my_script} action-{{item.0}} "{{hostvars[item.1]['some_fact']}}"
  8.       with_nested:
  9.         - group_list
  10.         - groups[item.0]

What happens is that ansible interprets "groups[item.0]" as a string and tries to iterate over it's characters.  Seems like a valid use case, but I can understand that re-evaluating the inner list on each outer-loop may be challenging. 

It's easily enough accomplished by unrolling the outer loop, but moderately annoying that I can't reduce it to a nested loop.




Reply all
Reply to author
Forward
0 new messages