Single and Double Quotations in Ansible

Hi There- While doing exercises, I’m required to use quotation marks around variables,
or when using loops and retrieving items etc… sometimes for the correct answer. Could someone advise on the usage of quotes in Ansible?

hi @gauravk,

When to quote variables (a YAML gotcha)

If you start a value with {{ foo }} , you must quote the whole expression to create valid YAML syntax. If you do not quote the whole expression, the YAML parser cannot interpret the syntax - it might be a variable or it might be the start of a YAML dictionary. For guidance on writing YAML, see the YAML Syntax documentation.

If you use a variable without quotes like this:

  • hosts: app_servers vars: app_path: {{ base_path }}/22

You will see: ERROR! Syntax Error while loading YAML. If you add quotes, Ansible works correctly:

  • hosts: app_servers vars: app_path: “{{ base_path }}/22”