user3313834
user3313834

Reputation: 7827

ansible: when condition with var from include

With ansible 1.9.2 I have a role with::

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

in snippet.yml I have::

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

But I get this error message::

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

FATAL: all hosts have already failed -- aborting

When I use the fist syntax proposed by @arbabnazar::

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

I get this error::

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

FATAL: all hosts have already failed -- aborting

With the second syntax proposed by @arbabnazar::

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

I get this error::

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

FATAL: all hosts have already failed -- aborting

Upvotes: 3

Views: 123

Answers (1)

Arbab Nazar
Arbab Nazar

Reputation: 23791

Can you try this:

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

Upvotes: 1

Related Questions