Default role variables don't get displayed properly in playbook output

27 views
Skip to first unread message

Brian Picciano

unread,
Jun 13, 2015, 8:23:43 PM6/13/15
to ansible...@googlegroups.com
I have the following files:

roles/test/defaults/main.yml
---
test_var1: foo
test_var2: bar

roles/test/handlers/main.yml
---
- name: "Testing handler - {{ test_var1 }} {{ test_var2 }}"
 debug: var=test_var2


roles/test/tasks/main.yml
---
- name: "Testing task - {{ test_var1 }}"
 debug: var=test_var1 
 changed_when: True
 notify:
   - "Testing handler - {{ test_var1 }} {{ test_var2 }}"

playbooks/test.yml
---
- hosts: all
  roles:
   - role: test
     test_var1: FOO
     test_var2: BAR

And running the test.yml playbook gives the following output:

TASK: [test | Testing task - FOO] *********************************************  
changed
: [127.0.0.1] => {
   
"changed": true,  
   
"var": {
       
"test_var": "FOO"
   
}
}
 
NOTIFIED
: [test | Testing handler - FOO BAR] **********************************  
ok
: [127.0.0.1] => {
   
"var": {
       
"test_var2": "BAR"
   
}
}

However, if I comment out the test_var2 instance in playbooks/test.yml, like this:

--- 
- hosts: all 
  roles: 
   - role: test 
     test_var1: FOO 
     #test_var2: BAR

Then the output looks like this:

TASK: [test | Testing task - FOO] *********************************************  
changed
: [127.0.0.1] => {
   
"changed": true,  
   
"var": {
       
"test_var": "FOO"
   
}
}
 
NOTIFIED
: [test | Testing handler - {{ test_var1 }} {{ test_var2 }}] **********  
ok
: [127.0.0.1] => {
   
"var": {
       
"test_var2": "bar"
   
}
}

In the NOTIFIED output the test variables don't actually get filled in, but in the previous output they were. Am I doing something wrong here or is this some kind of bug with ansible?

This is all on ansible 1.9.1, on CentOS7

Mark van der Hout

unread,
Jun 19, 2015, 5:15:02 AM6/19/15
to ansible...@googlegroups.com

Confirmed.

For me it also doesn't work if I give the vars through the CLI with --extra-vars "test_var2 = TESTBAR"

Brian Coca

unread,
Jun 19, 2015, 10:24:15 AM6/19/15
to ansible...@googlegroups.com
try removing the spaces --extra-vars "test_var2=TESTBAR"


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages