dynamic inventory tiered groups

Hello!

I’m new to ansible, and I am trying to figure out how the json output should look like if I have a flat-file inventory source like:

application:environment=hostlist

heroes:marvel=thor hulk stark cap
heroes:dc=supe bats flash robin
colors:primary=red blue yellow
colors:secondary:green orange violet

lol:~/scripts/python bash-3.2$ ./inv.py --list

{
“heroes”: {
“dc”: [
“supe”,
“bats”,
“flash”,
“robin”
],
“marvel”: [
“thor”,
“hulk”,
“stark”,
“cap”
]
},
“colors”: {
“primary”: [
“red”,
“blue”,
“yellow”
],
“secondary”: [
“green”,
“orange”,
“violet”
]
}
}

I am looking to run one liners against groups and sub groups such as:

ansible -i ~/bin/inv.py colors -m ‘uname -n’
(runs uname against red, blue, yellow, green, orange, violet)

ansible -i ~/bin/inv.py primary -m ‘uname -n’

(runs uname against green, orange, violet)

Or, I could be going about this all wrong. Can anyone give me a hint?

cheers,
Marc