Need help to automate tasks.

46 views
Skip to first unread message

abhay gupta

unread,
Oct 27, 2017, 6:55:37 AM10/27/17
to Ansible Project
Hello Friends,

I need your help to finish my task.

In my playbook, we are starting a web server which took almost 4-7 minutes.
I need to write a task, in which we need to hit a wsdl in after 1 minute and if we are getting the 200 response message as a response. need to print a message" Web server is up and running". 
And if after some time, let's say till 10 minutes if the wsdl is not getting the 200 response message, it should say, "Web server is not correctly deployed."

Thanks.
Abhay.

J Hawkesworth

unread,
Oct 29, 2017, 5:34:19 AM10/29/17
to Ansible Project
You can do something like this (thanks to Matt Martz who originally suggested it)

- name: check if app is up and ready to serve the wsdl
  uri:
    url: 'http://{{ inventory_hostname }}/app/app.wsdl'
    return_content: yes
    timeout: 2
  delegate_to: localhost
  register: poll_result
  until: poll_result['status']|default(0) == 200
  retries: 40
  delay: 3

This tries the url every 3 seconds for a maximum of 40 attempts.

Hope this helps,

Jon

J Hawkesworth

unread,
Oct 29, 2017, 5:37:20 AM10/29/17
to Ansible Project
Oh, I meant to say you can use the block...rescue ... allways with 'debug' module to display the messages you want.

See http://docs.ansible.com/ansible/latest/playbooks_blocks.html
and http://docs.ansible.com/ansible/latest/debug_module.html

Jon

abhay gupta

unread,
Oct 30, 2017, 3:43:31 AM10/30/17
to Ansible Project
Thanks Jon....
I am able to complete my task now.......

Abhay Gupta....
Reply all
Reply to author
Forward
0 new messages