Given this YAML:
somevar:
alpha:
beta:
gamma:
foo1: bar1
foo2: bar2
red:
green:
blue:
baz1: quz1
baz2: quz2
I want to construct strings of the full key paths:
somevar/alpha/beta/gamma
somevar/red/green/blue
Thanks.
Given this YAML:
somevar:
alpha:
beta:
gamma:
foo1: bar1
foo2: bar2
red:
green:
blue:
baz1: quz1
baz2: quz2
I want to construct strings of the full key paths:
somevar/alpha/beta/gamma
somevar/red/green/blue
Thanks.
There is no built in way to do this, however with a new custom filter, maybe you can get it:
def dict_path(my_dict, path=None):
if path is None:
path =
for k, v in my_dict.iteritems():
newpath = path + [k]
if isinstance(v, dict):
for u in dict_path(v, newpath):
yield u
else:
yield newpath, v
class FilterModule(object):
def filters(self):
return {
‘dict_path’: dict_path
}
And then a playbook that makes use of this:
That worked perfectly – thanks so much!