Skip to content

Instantly share code, notes, and snippets.

@srgvg
Last active December 17, 2015 11:49
Show Gist options
  • Save srgvg/5605645 to your computer and use it in GitHub Desktop.
Save srgvg/5605645 to your computer and use it in GitHub Desktop.
test inventory and commands showing a problem with variable precedence
# app1 var=app1 app2 var=app2
# / \ / \
# app1-dev app1-prod app2-dev app2-prod var=app{1,2}-{dev,prod} (set to respective groupname)
# / \ / \
# app1-dev-node app1-prod-node app2-dev-node app2-prod-node ${group}-node is the single member of $group
#
# each node ${group}-node should get as value for $var -> ${group}
# being the value of its respective group name ${group}
# test command:
# ansible -o -m debug -a msg="{{var}}" all -c local -i hosts
# groups as per graph
[app1:children]
app1-dev
app1-prod
[app2:children]
app2-dev
app2-prod
[app1-dev]
app1-dev-node
[app1-prod]
app1-prod-node
[app2-dev]
app2-dev-node
[app2-prod]
app2-prod-node
#### VARS #####
## var is set to the respective group name
[app1:vars]
var=app1
[app2:vars]
var=app2
[app1-dev:vars]
var=app1-dev
[app2-dev:vars]
var=app2-dev
[app1-prod:vars]
var=app1-prod
[app2-prod:vars]
var=app2-prod
ansible -o -m debug -a msg={{var}} all -c local -i inventory/ini/hosts
app1-prod-node | success >> {"msg": "app1-prod"}
app1-dev-node | success >> {"msg": "app1-dev"}
app2-dev-node | success >> {"msg": "app2-dev"}
app2-prod-node | success >> {"msg": "app2-prod"}
ansible -o -m debug -a msg={{var}} all -c local -i inventory/ini
app2-dev-node | success >> {"msg": "app2-dev"}
app1-prod-node | success >> {"msg": "app1-prod"}
app1-dev-node | success >> {"msg": "app1"}
app2-prod-node | success >> {"msg": "app2"}
ansible -o -m debug -a msg={{var}} all -c local -i inventory
app2-dev-node | success >> {"msg": "app2-dev"}
app1-prod-node | success >> {"msg": "app1-prod"}
app1-dev-node | success >> {"msg": "app1"}
app2-prod-node | success >> {"msg": "app2"}
@mpdehaan
Copy link

mpdehaan commented Jun 3, 2013

Ok, I see now, this is a bug that only occurs when the inventory is sourced from a directory. I see now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment