How Do You Troubleshoot the Ansible Message “Syntax Error while loading YAML. expected , but found ””?

Problem scenario
You run an Ansible playbook with a variable. But you get this message: "ERROR! Syntax Error while loading YAML. expected , but found ''" (Ansible found blank single quotes or a double quote mark.)

How do you get the playbook to run?

Notice the "offending line" in the message. Remove the braces and possibly the quotes around the braces. Assign the variable by itself (without the braces syntax).

Do not use a variable like this:

     - shell: "echo  > /tmp/date.txt"
       when: {{ ansible_hostname }} == "contintserver"

or like this:

- shell: "echo  > /tmp/date.txt"
  when: "{{ ansible_hostname }}" == "contintserver"

Here would be a correct snippet:

- shell: "echo  > /tmp/date.txt"
  when: ansible_hostname == "contintserver"

Leave a comment

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