# Roles, vars, defaults, and pre\_tasks.

**URL:** <https://forum.ansible.com/t/roles-vars-defaults-and-pre-tasks/23903>\
**Category:** Ansible Project\
**Created:** [March 7, 2017, 10:28pm UTC](https://forum.ansible.com/t/roles-vars-defaults-and-pre-tasks/23903 "2017-03-07T22:28:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [March 7, 2017, 10:28pm UTC](https://forum.ansible.com/t/roles-vars-defaults-and-pre-tasks/23903/1 "2017-03-07T22:28:08Z")

</div>

I’m trying to split up a large playbook into roles and it’s going pretty well except I’m having trouble with variables not being pulled in from the roles vars or defaults files.

My playbook has this test playbook with a pre\_task:

> * * *
> 
> - hosts: all
> 
> # vars:
> 
> # doreboots: true
> 
> # zadmin\_password: Today123zadmin
> 
> # root\_password: Today123
> 
> pre\_tasks:
> 
> - debug:
> 
> msg: “Playbook WILL REBOOT when requested.”
> 
> when: doreboots
> 
> roles:
> 
> - setup\_ansible\_data

I’ve moved the “vars:” section (commented out above) to the main.yml files in both the “vars” and “defaults” directories like this:

> * * *
> 
> doreboots: true

When the playbook is run, I get this error:

> TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> fatal: [[system.example.com](http://system.example.com)]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘doreboots’ failed. The error was: error while evaluating conditional (doreboots): ‘doreboots’ is undefined\n\nThe error appears to have been in ‘/etc/ansible/roles/sysprep/test.yml’: line 10, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n pre\_tasks:\n - debug:\n ^ here\n”}

Or more human readable:

> The conditional check ‘doreboots’ failed. The error was: error while evaluating conditional (doreboots): ‘doreboots’ is undefined
> 
> The error appears to have been in ‘/etc/ansible/roles/sysprep/test.yml’: line 10, column 7, but may
> 
> be elsewhere in the file depending on the exact syntax problem.
> 
> The offending line appears to be:
> 
> pre\_tasks:
> 
> - debug:
> 
> ^ here

Thoughts?

Thanks!  
Dan

---

<div class="post-metadata">

**Author:** ![Simon\_Wydooghe](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Simon\_Wydooghe](https://forum.ansible.com/u/Simon_Wydooghe)\
**Post date:** [March 10, 2017, 12:17pm UTC](https://forum.ansible.com/t/roles-vars-defaults-and-pre-tasks/23903/2 "2017-03-10T12:17:39Z")

</div>

Hey Dan,

It seems you have two spaces in front of the variable, I’m not sure if that poses a problem, but maybe try putting it like this:

`
