Hi again,
I'm looking for a way to merge multiple lists into one. Difficulty is that the
lists have dynamic names.
E.g.
#### cluster.yaml ####
---
racks: ['rack01', 'rack02'] # might be many more racks
######################
#### rack01.yaml ####
---
rack_number: 1
compute_nodes: ['alpha', 'bravo']
#####################
#### rack02.yaml ####
---
rack_number: 2
compute_nodes: ['charlie', 'delta']
#####################
#### playbook ####
---
- hosts: localhost
connection: local
gather_facts: false
tasks:
- include_vars:
file: cluster.yaml
name: cluster
- include_vars:
file: '{{ item }}.yaml'
name: '{{ item }}'
with_items: '{{ cluster.racks }}'
- set_fact: all_nodes='some powerful magic that merges rack01.compute_nodes
… rackNN.compute_nodes'
- debug: var=all_nodes
##################
Expected result: all_nodes: ['alpha', 'bravo', 'charlie', 'delta']
This snippet doesn't work due to undefined variables (which I was trying to
capture with default filter):
####
- set_fact: all_nodes='{{ all_nodes | default(None) }} + {{
item.compute_nodes }}'
with_items: '{{ cluster.racks }}'
####
But I suspect that the undefined variable isn't "all_nodes" but that item
(cluster.racks.[X]) is a string and not the
rackXX variable.
So the question probably is "how to access a variable who's name is stored in
another variable"? And how to do so in a loop?
Any suggestions on how to implement this in a different way?
Regards,
Uwe
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/55e09df0-c0c0-2481-61d0-8657c72f151d%40gmail.com.
For more options, visit https://groups.google.com/d/optout.