Last active
December 17, 2015 11:49
-
-
Save srgvg/5605645 to your computer and use it in GitHub Desktop.
test inventory and commands showing a problem with variable precedence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} | |
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
I'm also not seeing this with your inventory file:
changed: [app1-prod-node] => {"changed": true, "cmd": "echo app1-prod ", "delta": "0:00:00.013328", "end": "2013-06-03 11:04:34.203140", "rc": 0, "start": "2013-06-03 11:04:34.189812", "stderr": "", "stdout": "app1-prod"}
changed: [app2-dev-node] => {"changed": true, "cmd": "echo app2-dev ", "delta": "0:00:00.007843", "end": "2013-06-03 11:04:34.195328", "rc": 0, "start": "2013-06-03 11:04:34.187485", "stderr": "", "stdout": "app2-dev"}
changed: [app1-dev-node] => {"changed": true, "cmd": "echo app1-dev ", "delta": "0:00:00.009514", "end": "2013-06-03 11:04:34.198233", "rc": 0, "start": "2013-06-03 11:04:34.188719", "stderr": "", "stdout": "app1-dev"}
changed: [app2-prod-node] => {"changed": true, "cmd": "echo app2-prod ", "delta": "0:00:00.017595", "end": "2013-06-03 11:04:34.209548", "rc": 0, "start": "2013-06-03 11:04:34.191953", "stderr": "", "stdout": "app2-prod"}