Roles, vars, defaults, and pre_tasks.

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]: 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

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:

`