Hi ,

I have a playbook  with the  below lines .

$ cat double_check.yml
---
- name: playbook to test the status of the web
  hosts: centos8-latest
  tasks:
    - block:
        - name: Install the  httpd packages
          ansible.builtin.yum:
            name: httpd
            state: latest

        - name: Enable and Start the httpd service
          ansible.builtin.service:
            name: httpd
            state: started
            enabled: true

        - name: Check web site from web server
          ansible.builtin.uri:
            url: http://{{ ansible_fqdn }}
            return_content: true
            status_code: 200
          register: example_webpage
          failed_when: example_webpage.status != 200



      rescue:
        - name: Restart web server
          ansible.builtin.service:
            name: httpd
            state: restarted

#we still can have handlers to  demo this playbook  

This Playbook works as expected  until  the status code is 200.
[user@centos8-latest html]$ ls -l
total 4
-rw-r--r-- 1 root root 104 Jul 28 10:36 index.html
[user@centos8-latest html]#

If there is no index.html , CentOS/redhat  shows its  apache foundation 
page which is returning a different  status code[409 ] . which is causing 
the task to fail .

I am expecting  the Status Code 200  [success] ,  409[already running] and 
404/others[failed]
How can we handle this error?  Ignore_error=yes  is not required.
If  Status Code = 200 , then no change required . ( a handler to be called  
after that )
if status code=409 , it should pass and still continue to next task (if 
added). (no handler to be called  )
other codes/404 can fail.


Is there an option to declare "status code =200 or 409 "in the single line?
Or we have to  handle them with 2 different play ? possible ?





-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8a3da674-b6cb-4868-ae41-9d690f7b6ca9n%40googlegroups.com.

Reply via email to