1

I'm using Ansible 2.0.1.0.

In my main.yml I have this task:

- name: hoge
  hosts: hoge2
  connection: docker
  become: yes
  become_user: {{ansible_user}}

When executing, I get this error message:

ERROR! Syntax Error while loading YAML.

The error appears to have been in '/Users/fuga/Docker/ansible/main.yml': line 16, column 17, but maybe elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  become: yes
  become_user: {{ansible_user}}
                ^ here

How can I fix the error?

jaygooby
  • 2,436
  • 24
  • 42
user3387068
  • 151
  • 1
  • 2
  • 14

1 Answers1

3

In YAML a { starts a dictionary. Therefore you need to quote the expression.

become_user: "{{ansible_user}}"

See Gotchas in the Ansible YAML docs.

udondan
  • 57,263
  • 20
  • 190
  • 175