Playbook variables, documentation confusing

Dear list,

I am using the tip of Ansible development:

  % ansible-playbook --version
  ansible-playbook 1.3 (devel 0bd5fe9951) last updated 2013/06/15 16:06:49 (GMT +200)

On http://www.ansibleworks.com/docs/playbooks.html, I read the
following paragraph (under "Vars section"):

  These variables can be used later in the playbook like this:

    $varname or ${varname} or {{ varname }}

  If you ever want to do anything complex like uppercasing a string,
  {{ varname }} is best, as it uses the Jinja2 templating engine. It
  is a good idea to get in the habit of using this form most of the
  time when the output is to be a string.

However, if I try to use the Jinja2-syntax in a playbook, I get an
error:

  % ansible-playbook motd.yml
  ERROR: Syntax Error while loading YAML script, motd.yml
  Note: The error may actually appear before this position: line 6, column 16

    - role: motd
      override: {{motd.override}}

While trying to figure out what is going on, I found that
docsite/playbooks.html severly differs from the online
documentation. Specifically, under "Vars section", there is no
mention of the ability to use the Jinja2-syntax in a playbook.

What's going on? Am I wrong in assuming that docsite/* in the source
checkout should be /more/ up-to-date than the website?

I have also set

  legacy_playbook_variables=no

in ~/.ansible.cfg, but I can use $variable just like before, without
any problems. In fact, that's the only way to access a variable.

Any clues?

Not sure if you can use the override with rolls there, but guess you need to indent it with 2 spaces.

also sprach Vincent Van der Kussen <vincent.vanderkussen@gmail.com> [2013.06.15.1621 +0200]:

Not sure if you can use the override with rolls there,

Yes, I can, and it works. The problem is with the expansion of
variables.

but guess you need to indent it with 2 spaces.

Nope, that would be invalid syntax. The syntax is fine.

I was guessing because i saw this

% ansible-playbook motd.yml
ERROR: Syntax Error while loading YAML script, motd.yml

also sprach Vincent Van der Kussen <vincent.vanderkussen@gmail.com> [2013.06.15.1640 +0200]:

I was guessing because i saw this

  % ansible-playbook motd.yml
  ERROR: Syntax Error while loading YAML script, motd.yml

That was a good spot. It turs out that

  - role: test
    override: {{override}}

is a syntax error, due to the {} characters. Doing this:

  - role: test
    override: '{{override}}'

instead works.

And it makes sense when you think of it. python-yaml parses the YAML
file and only then does Ansible run the data through Jinja2 for
interpolation. Since {} are reserved characters in YAML, they need
to be quoted.

Thanks, Vincent, your hawk eye and patience allowed me to figure
this out.

This still leaves the differences between the in-checkout
documentation and the website…

The website was normally refreshed manually, a certain lag was expected. That said, recently there have been major changes in location and style so not sure if /docsite is still relevant.

docsite is still quite active in the repository and is the source of all documentation still.

Don’t worry, nothing has changed!

We just haven’t pushed updates every single day because of being engaged with AnsibleFest!