Looping over map key:value pairs? #2458
Unanswered
IAMSolaara
asked this question in
Q&A
Replies: 2 comments
-
I guess one way to do this would be turning the map into a list of maps, thus getting: NODES:
- map:
key: foo
type: a
- map:
key: bar
type: a
- map:
key: baz
type: b |
Beta Was this translation helpful? Give feedback.
0 replies
-
@IAMSolaara When looping over maps, we make the tasks:
map_test:
vars:
NODES_MAP:
map:
foo: { type: a }
bar: { type: a }
baz: { type: b }
cmd:
for: { var: NODES_MAP }
cmd: "echo map key: {{.KEY}} - {{.ITEM}}" |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have seen that you can loop over a map variable using
for
, but it loops over the values, not keys or key:value pairs.I have this task declared:
And thus get as output:
which just gives me the values, but not the keys.
Is there a way to loop over a key:value pair, like a record? Am I missing something?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions