nested with_items

I have a senerio where i think a nested with_items would work , but i am not seeing any examples where there are multiple keys.

Today i have a with_items that looks like this:

`

  • name: Include vmware workflow for Tag Setups
    include_tasks: tasks/vmworkflow_assetgroup_create_tags_include.yml
    with_items:
  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ }
  • {segname: ‘bu2’, segabv: ‘2’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu2’ }
  • {segname: ‘bu3’, segabv: ‘3’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu3’ }
  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image with DB Backup’, ptype: ‘pd’, driveselect: ‘2’, ret: ‘30’, tagtype: ‘DB Backup’, tagbg: ‘bu1’ }
  • {segname: ‘bu2’, segabv: ‘2’, btype: ‘Image with DB Backup’, ptype: ‘pd’, driveselect: ‘2’, ret: ‘30’, tagtype: ‘DB Backup’, tagbg: ‘bu2’ }
  • {segname: ‘bu3’, segabv: ‘3’, btype: ‘Image with DB Backup’, ptype: ‘pd’, driveselect: ‘2’, ret: ‘30’, tagtype: ‘DB Backup’, tagbg: ‘bu3’ }

`

But i need to repeat each of these with two more pecies of data and thought a nested would be better than created 7 more of each one listed above.

I need to device enviornment with prod or nonprod and time with 1800, 2200, 0200, 0400

so the included task would then have :

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } prod 1800

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } prod 2200

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } prod 0200

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } prod 0400

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } nonprod 1800

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } nonprod 2200

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } nonprod 0200

  • {segname: ‘bu1’, segabv: ‘1’, btype: ‘Image Backup’, ptype: ‘pi’, driveselect: ‘0’, ret: ‘30’, tagtype: ‘Image Only’, tagbg: ‘bu1’ } nonprod 0400

all as variables that i can call within the include. Currently i am calling the rest with item.segname, item.segabv, etc…

thoughts or am i stuck with just having a longer list of with items?

I usually handle this by looping over include_tasks. So each level has its own file with tasks, and includes another task to ‘go down’ one level so to speak.

So with that option I would have two more include tasks prior where I set the the next to vars?

Any other options to keep it in one play?

So with that option I would have two more include tasks prior where I set the the next to vars?

Any other options to keep it in one play?

You could also use the product filter
(https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#product-filters):

Assign your current list to a variable, e.g asset_list and combine it with lists for environment and time:

with_items: "{{ asset_list | product(['prod', 'nonprod']) | product(['1800', '2200', '0200', '0400']) }}"

This will run over all possible combinations of the items in these three lists.

Regards
       Racke

How do I access that as a var? I am accessing each component as part of a uri call in the include tasks statement.