Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/msabramo/ansible-roles-example
Demonstration of unexpected behavior with roles and variable scope
https://github.com/msabramo/ansible-roles-example
Last synced: about 1 month ago
JSON representation
Demonstration of unexpected behavior with roles and variable scope
- Host: GitHub
- URL: https://github.com/msabramo/ansible-roles-example
- Owner: msabramo
- Created: 2014-07-02T15:39:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-02T15:57:24.000Z (over 10 years ago)
- Last Synced: 2024-05-09T20:47:14.482Z (8 months ago)
- Size: 121 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An experiment with ansible roles and variable scope
Deals with topic mentioned in this thread:
https://groups.google.com/forum/#!topic/Ansible-project/yrnsx2Mw6rc
This defines a playbook with 3 roles:
- foo
- bar
- dogEach role does an include to pick up a task in another role called
"pythonapp" - this task simply prints out the value of a variable called
`sm_app_role`.The roles are supposed to define the `sm_app_role` variable in a
`vars/main.yml` file...But we neglect to do this in the `bar` role (simulating programmer
error)...Since I thought that variables are scoped to roles, I expected this output:
TASK: [bar | print value of sm_app_role] **************************************
ok: [localhost] => {
"sm_app_role": "{{ sm_app_role }}"
}But instead I get this:
TASK: [bar | print value of sm_app_role] **************************************
ok: [localhost] => {
"sm_app_role": "dog"
}The latter seems to suggest that in at least some cases there is leakage of
variables from one role to another. Why?Output:
```
$ ansible-playbook -vvv -i hosts playbook.ymlPLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
REMOTE_MODULE setup
EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1404315384.66-20719838060817 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1404315384.66-20719838060817 && echo $HOME/.ansible/tmp/ansible-tmp-1404315384.66-20719838060817']
PUT /var/folders/gw/w0clrs515zx9x_55zgtpv4mm0000gp/T/tmpBZ1TEE TO /Users/marca/.ansible/tmp/ansible-tmp-1404315384.66-20719838060817/setup
EXEC ['/bin/sh', '-c', u'LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8 /usr/bin/python /Users/marca/.ansible/tmp/ansible-tmp-1404315384.66-20719838060817/setup; rm -rf /Users/marca/.ansible/tmp/ansible-tmp-1404315384.66-20719838060817/ >/dev/null 2>&1']
ok: [localhost]TASK: [foo | print value of sm_app_role] **************************************
ok: [localhost] => {
"sm_app_role": "foo"
}TASK: [bar | print value of sm_app_role] **************************************
ok: [localhost] => {
"sm_app_role": "dog"
}TASK: [dog | print value of sm_app_role] **************************************
ok: [localhost] => {
"sm_app_role": "dog"
}PLAY RECAP ********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0$ ansible-playbook --version
ansible-playbook 1.6.5
```