when ‘when’ starts with a string

George Shuklin
OpsOps
Published in
1 min readAug 2, 2018

It’s a small post about trivial thing, but someone need to write it down.

Let’s say we have a playbook:

- foo: args=args
when: 'foo' in bar

Unfortunately, we can’t use this, because of “ERROR! Syntax Error while loading YAML”, and a lengthy explanation will follow:

This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:

when: “ok” in result.stdout

Could be written as:

when: ‘“ok” in result.stdout’

Or equivalently:

when: “‘ok’ in result.stdout”

Meh… Putting everything is quotes? It will break all syntax highlighting, and eat way quotation level. There is a better fix:

- foo: args=args
when: ('foo' in bar)

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.