ansible:当条件与 var from include

标签 ansible

对于 ansible 1.9.2,我有一个角色::

- include: snippet.yml repo=rep1
- include: snippet.yml repo=rep2
- include: snippet.yml repo=rep2

snippet.yml 我有::

- name: debug
  debug: msg='hello'
  when: rep1 == {{ repo }}

但我收到此错误消息::

fatal: [vagrant] => error while evaluating conditional: rep1 == rep1

FATAL: all hosts have already failed -- aborting

当我使用@arbabnazar::提出的拳头语法时

- name: debug
  debug: msg='hello'
  when: "rep1 == {{ repo }}"

我收到这个错误::

TASK: [stack | debug] *******************************************
fatal: [vagrant] => error while evaluating conditional: rep1 == rep1

FATAL: all hosts have already failed -- aborting

使用@arbabnazar::提出的第二种语法

- name: debug
  debug: msg='hello'
  when: "rep1 in {{ repo }}"

我收到这个错误::

TASK: [stack | debug] *******************************************
fatal: [vagrant] => error while evaluating conditional: rep1 in rep1

FATAL: all hosts have already failed -- aborting

最佳答案

你能试试这个吗:

- name: debug
  debug: msg='hello'
  when: repo  == "repo1"

关于ansible:当条件与 var from include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36908367/

相关文章:

比较整数值时的ansible

Ansible 检查特定目录是否存在,如果不存在则创建它

shell - 使用 "become: true"在 Ansible 不工作的情况下更改默认 shell

linux - 是否有用于写入 ini 文件的 GNU/Linux 命令?

Ansible - 如何在远程服务器中使用查找

ansible - 在 ansible_hostname 中查找子字符串

Ansible 中的 SSH 错误 : Permission denied (publickey, 密码)

ansible - 如果条件为真,则运行一些包含 yml 文件

ansible - 防止 Ansible 中变量转换为 bool

ansible - 在 Ansible 中使用 `start-at-task` 时,是否可以强制始终运行较早的任务?