Ansible "failed_when" not working as desired

72 views
Skip to first unread message

Rakesh Parida

unread,
Mar 6, 2020, 7:46:58 AM3/6/20
to Ansible Project
Hi,

I have a task as follows:

- hosts: nodes
  gather_facts: true
  tasks:
    - name: CurlCP Status
      shell: "curl -Is -m 1 http://localhost:9113/cp/healthcheck"
      register: cp_status
      failed_when: "'200 OK' not in cp_status.stdout_lines"

It fails even if 200 Ok is in o/p. I want to fail the job only when 200 OK is not in o/p
Pls help here

Vladimir Botka

unread,
Mar 6, 2020, 8:26:07 AM3/6/20
to Rakesh Parida, ansible...@googlegroups.com
On Fri, 6 Mar 2020 04:46:58 -0800 (PST)
Rakesh Parida <rakeshp...@gmail.com> wrote:

> failed_when: "'200 OK' not in cp_status.stdout_lines"

Try

failed_when: cp_status.stdout_lines|
select('search', '200 OK')|
list|
length == 0

HTH,

-vlado

Dick Visser

unread,
Mar 6, 2020, 8:29:10 AM3/6/20
to ansible...@googlegroups.com
Why not use the uri module instead of fragile shell + curl ?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6589d432-2ae7-4fcb-a7ba-926cfb3f2a17%40googlegroups.com.


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
Reply all
Reply to author
Forward
0 new messages