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

查看:41
本文介绍了在 become_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 文档中的问题.

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

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