在begin_user中使用变量时出现Ansible语法错误 [英] Ansible syntax error when using variable in become_user

查看:128
本文介绍了在begin_user中使用变量时出现Ansible语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ansible 2.0.1.0.

I'm using Ansible 2.0.1.0.

在我的main.yml中,我有以下任务:

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

如何解决该错误?

推荐答案

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

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

become_user: "{{ansible_user}}"

请参阅Ansible YAML文档中的 Gotchas .

See Gotchas in the Ansible YAML docs.

这篇关于在begin_user中使用变量时出现Ansible语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆