ansible:当包含var的条件时

时间:2016-04-28 07:44:30

标签: 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

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

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