1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adding an integration test for variable precedence

This commit is contained in:
James Cammarata 2014-05-09 11:42:45 -05:00
parent b78058022d
commit 272db903e5
15 changed files with 102 additions and 0 deletions

View file

@ -35,6 +35,9 @@ test_hash:
ANSIBLE_HASH_BEHAVIOUR=replace ansible-playbook test_hash.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' ANSIBLE_HASH_BEHAVIOUR=replace ansible-playbook test_hash.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}'
ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}' ANSIBLE_HASH_BEHAVIOUR=merge ansible-playbook test_hash.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e '{"test_hash":{"extra_args":"this is an extra arg"}}'
test_var_precedence:
ansible-playbook test_var_precedence.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v -e 'extra_var=extra_var'
cloud: amazon rackspace cloud: amazon rackspace
cloud_cleanup: amazon_cleanup rackspace_cleanup cloud_cleanup: amazon_cleanup rackspace_cleanup

View file

@ -8,3 +8,6 @@ test_hash:
# Support execution from within a virtualenv # Support execution from within a virtualenv
ansible_python_interpreter: '/usr/bin/env python' ansible_python_interpreter: '/usr/bin/env python'
# Var precedence testing
defaults_file_var_role3: "overridden from inventory"

View file

@ -0,0 +1,4 @@
dependencies:
- { role: test_var_precedence_role1, param_var: "param_var_role1" }
- { role: test_var_precedence_role2, param_var: "param_var_role2" }
- { role: test_var_precedence_role3, param_var: "param_var_role3" }

View file

@ -0,0 +1,5 @@
- assert:
that:
- 'extra_var == "extra_var"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'

View file

@ -0,0 +1,5 @@
---
# should be overridden by vars_files in the main play
vars_files_var: "BAD!"
# should be seen in role1 (no override)
defaults_file_var_role1: "defaults_file_var_role1"

View file

@ -0,0 +1,12 @@
- debug: var=extra_var
- debug: var=param_var
- debug: var=vars_var
- debug: var=vars_files_var
- debug: var=defaults_file_var_role1
- assert:
that:
- 'extra_var == "extra_var"'
- 'param_var == "param_var_role1"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'defaults_file_var_role1 == "defaults_file_var_role1"'

View file

@ -0,0 +1,3 @@
---
# should override the global vars_files_var since it's local to the role
vars_files_var: "vars_files_var_role1"

View file

@ -0,0 +1,5 @@
---
# should be overridden by vars_files in the main play
vars_files_var: "BAD!"
# should be overridden by the vars file in role2
defaults_file_var_role2: "BAD!"

View file

@ -0,0 +1,12 @@
- debug: var=extra_var
- debug: var=param_var
- debug: var=vars_var
- debug: var=vars_files_var
- debug: var=defaults_file_var_role1
- assert:
that:
- 'extra_var == "extra_var"'
- 'param_var == "param_var_role2"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'defaults_file_var_role2 == "overridden by role vars"'

View file

@ -0,0 +1,5 @@
---
# should override the global vars_files_var since it's local to the role
vars_files_var: "vars_files_var_role1"
# should override the value in defaults/main.yml for role 2
defaults_file_var_role2: "overridden by role vars"

View file

@ -0,0 +1,7 @@
---
# should be overridden by vars_files in the main play
vars_files_var: "BAD!"
# should override the defaults var for role 1 and 2
defaults_file_var: "last one wins"
# should be overridden from the inventory value
defaults_file_var_role3: "BAD!"

View file

@ -0,0 +1,12 @@
- debug: var=extra_var
- debug: var=param_var
- debug: var=vars_var
- debug: var=vars_files_var
- debug: var=defaults_file_var_role1
- assert:
that:
- 'extra_var == "extra_var"'
- 'param_var == "param_var_role3"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'defaults_file_var_role3 == "overridden from inventory"'

View file

@ -0,0 +1,3 @@
---
# should override the global vars_files_var since it's local to the role
vars_files_var: "vars_files_var_role1"

View file

@ -0,0 +1,19 @@
---
- hosts: testhost
vars:
- vars_var: "vars_var"
- param_var: "BAD!"
- vars_files_var: "BAD!"
vars_files:
- vars/test_var_precedence.yml
roles:
- { role: test_var_precedence, param_var: "param_var" }
tasks:
- debug: var=extra_var
- debug: var=vars_var
- debug: var=vars_files_var
- assert:
that:
- 'extra_var == "extra_var"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'

View file

@ -0,0 +1,4 @@
---
extra_var: "BAD!"
role_var: "BAD!"
vars_files_var: "vars_files_var"