variables in with_items:

Hi all, can someone help me with a problem - I get some facts from my xenserver… the i want to use the version fact to get a list of required hotfixes i use:

with_items:

  • “${ansible_xenserver_version}-hotfixes”

to return “6.2.0-hotfixes”.

i want to use the items in that var list. but instead it just uses “6.2.0-hotfixes” as the item. How do i get ansible to use that as the pointer not an absolute value? similar to

with_items:

  • ${groups.xen-hosts}

group_vars contains:

6.2.0-hotfixes:

  • XS62E001
  • XS62E002
  • XS62E004

Many thanks

Paul Angus
@CloudyAngus

with_items: groups.xen_hosts

with_items. groups[‘xen_hosts’]

Don’t use legacy variables.

1.4 will warn you about these things.

Got it.
…but what is the syntax of

with_items:

  • “{{ansible_xenserver_version}}-hotfixes”

to run through the groups_vars

6.2.0-hotfixes

?

Best practices would be to avoid performing variable name constructions programatically.

it would be better to store these in a hash and do

with_items: hotfixes[ansible_xenserver_version]