user3591144
user3591144

Reputation: 29

Ansible loops and conditionals

Ansible docs states that:

Combining when with with_items (see Loops), be aware that the when statement is processed separately for each item.

However when I try to skip one item in task, it doesn't work that way:

value_var: [1, 5]

- name: register variable
  command: echo "4"
  register: var

- name: conditional check
  command: nevermind
  when: var.stdout > item

By my understanding, that I would get changed on first item within conditional check task, and skipped on second item. But I get:

changed: [guest] => (item=5)
changed: [guest] => (item=1)

What am I doing wrong?

Upvotes: 1

Views: 255

Answers (1)

techraf
techraf

Reputation: 68459

It has nothing to do with loops. You are comparing a string (the result of echo command) with an integer.

You should first cast the value:

when: var.stdout|int > item

Upvotes: 1

Related Questions