在become_user中使用变量时出现Ansible语法错误

时间:2016-05-17 10:29:50

标签: ansible

我正在使用Ansible 2.0.1.0。

在我的main.yml我有这个任务:

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

执行时,我收到以下错误消息:

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

如何解决错误?

1 个答案:

答案 0 :(得分:2)

在YAML中,{启动字典。因此,您需要引用表达式。

become_user: "{{ansible_user}}"

请参阅Gotchas in the Ansible YAML docs