What Do You Do when an Ansible Playbook is Not Getting a Variable Assigned Properly?

Problem scenario
Ansible variables are not being picked up when the playbook runs. You may get no errors, or you may get errors like these:

"ERROR! Syntax Error while loading YAML…did not find expected key"

"ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path"

What should you do?

Possible Solution #1
Are you using the -i flag when you are running the command to execute the playbook? Did you recently start using a role instead of a playbook? The -i flag will prevent Ansible from looking in certain directories for an "all" file or "main.yml" file. If newly added variables are not being picked up, do you have them in different files? You may need to stick with one source file that works or change the directory from which you are running the playbook.

You may also want to see these links:

To learn about variable precedence, see this link.

Possible Solution #2
Put the end quotes at the end of the string rather than around the closing braces }}. Here is a line that would throw the error:
"{{ variable1 }}"/subdirectory/path/to/file

Here is a line that would not throw the error:
"{{ variable1 }}/subdirectory/path/to/file"

Possible Solution #3
From a pragmatic perspective, you may want to put the variables in a playbook and not in a role. This may help you avoid this error.

Possible Solution #4
You may want to view this posting when there are no visible errors when the playbook runs.

Leave a comment

Your email address will not be published. Required fields are marked *