Escaping problem with regular expression and variables

Hello,

I’m taking my first steps with Ansible (1.4 dev) and love it so far. However I hit a snag escaping special characters with a particular line. I’m trying to insert a line into a YAML file:

  • name: Insert clustername {{ clustername }}
    lineinfile:
    dest=/etc/elasticsearch/elasticsearch.yml
    regexp=‘^cluster.name: {{ clustername }}’
    line=‘cluster.name: “{{ clustername }}”’
    state=present

Both the regexp and the line expression give an error, either because of the variable brackets or because of the colon. (clustername is a simple string, no special characters).

I’ve tried a combination of single and double dashes, escaping just the regular expression or the whole argument, but can’t get it to work.

Any ideas?

Thank you,
christian

“Both the regexp and the line expression give an error”

Which error?

When reporting a problem on this list, always share the error.

Try YAML escaping the arguments with a ‘>’. That is,

lineinfile: >

dest=/etc/elasticsearch/elasticsearch.yml
regexp=‘[1](http://cluster.name): {{ clustername }}’
line=‘cluster.name: “{{ clustername }}”’
state=present


  1. cluster.name ↩︎

To be clear, that’s not escaping, that’s a line continuation.

Not quite - it does escape as well. That’s why the ': ’ sequence is not triggered.

K

More so that it knows you aren’t going to specifying another hash value.

See section 2.3 here:

http://www.yaml.org/spec/1.2/spec.html

True. I think said escaping when I meant quoting. Would be better to say it forces the following block to be interpreted as a scalar.

I’ve taken to always using the ‘>’ quoting mechanism even when not needed, because it avoids the whole confusing ‘colon’ + ‘space’ issue.

Enough said.

K