Ansible syntax error when using variable in become

2019-07-23 13:44发布

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?

标签: ansible
1条回答
贪生不怕死
2楼-- · 2019-07-23 14:33

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

become_user: "{{ansible_user}}"

See Gotchas in the Ansible YAML docs.

查看更多
登录 后发表回答