cancel
Showing results for 
Search instead for 
Did you mean: 
rehman0288
Mission Specialist
Mission Specialist
  • 2,402 Views

ansible fail module

Hi! I am having a problem with fail module in ansible. When I used it in a playbook, its executing fine but when I am trying to do the same thing with roles, its not working. I have defined exactly all variables in vars/main.yml and tasks/main.yml. All the tasks before the fail module are executing fine. Irrespective of the values defined, if I give max < total|int, it is always skipping and if I give max > total|int, it is always failing.

vars:

    max: 5000

    objects:

        - value: 1035

        - value: 3076

    total: 0

tasks:

    - set_fact:

          total: "{{ total }} + objects[{{ item }}].value"

       with_sequence: start=0 end="{{ objects | length - 1 }}"

    - debug:

          var:  "{{  total }}"

    - fail:

         msg:  "Failed"

      when: total|int  > max

Labels (1)
0 Kudos
1 Reply
Alexandre
Starfighter Starfighter
Starfighter
  • 2,344 Views

Solution:

Use at least version 2.7 of Ansible. Add jinja2_native = True to the [defaults] section of ansible.cfg (or set the environment variable ANSIBLE_JINJA2_NATIVE = True.)

Explanation:

In old version any value returned is a string so even if you used an int filter inside, the output is always rendered in as ansible string. Ansible 2.7 use a Jinja 2.10 function called Native Python Types and save the data type.

Join the discussion
You must log in to join this conversation.