Skip to content

Instantly share code, notes, and snippets.

@jimi-c
Created September 4, 2013 16:54
Show Gist options
  • Save jimi-c/6439723 to your computer and use it in GitHub Desktop.
Save jimi-c/6439723 to your computer and use it in GitHub Desktop.
# roles/test1/vars/main.yml
---
test_rolevars: TEST1_ROLEVARS
# roles/test1/tasks/main.yml
---
- debug: msg="testvar = {{ test_rolevars }}"
# roles/test2/vars/main.yml
---
test_rolevars: TEST2_ROLEVARS
# roles/test2/tasks/main.yml
---
- debug: msg="testvar = {{ test_rolevars }}"
$ ansible-playbook -i localhost, test.yml
PLAY [Test role defaults] *****************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [debug msg="testvar = TEST1_ROLEVARS"] **********************************
ok: [localhost] => {"item": "", "msg": "testvar = TEST1_ROLEVARS"}
TASK: [debug msg="testvar = TEST2_ROLEVARS"] **********************************
ok: [localhost] => {"item": "", "msg": "testvar = TEST2_ROLEVARS"}
PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
@such
Copy link

such commented Sep 4, 2013

# ./all.yml

---
- hosts: all
  roles:
   - role1
   - role2

# ./roles/role1/tasks/main.yml

---
- name: role1 step
  debug: msg="var={{ var }}"

# ./roles/role1/vars/main.yml

---
var: role1

# ./roles/role2/tasks/main.yml

---
- name: role2 step
  debug: msg="var={{ var }}"

# ./roles/role2/vars/main.yml

---
var: role2

# ./test
[all]
192.168.1.101


$ ansible-playbook -i test all.yml

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.1.101]

TASK: [role1 step] ************************************************************
ok: [192.168.1.101] => {"item": "", "msg": "var=role2"}

TASK: [role2 step] ************************************************************
ok: [192.168.1.101] => {"item": "", "msg": "var=role2"}

PLAY RECAP ********************************************************************
192.168.1.101              : ok=3    changed=0    unreachable=0    failed=0

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