trouble with shell and error-handling

52 views
Skip to first unread message

Trond Hindenes

unread,
Jul 28, 2015, 9:56:00 AM7/28/15
to Ansible Project
Hi all,
I'm trying to build some logic around rebooting Windows nodes and waiting until they come back online. I'm building a role to easily allow us to check for pending reboots and reboot if necessary as part of a playbook.

Since Ansible is using winrm I figured it best to using winrm for testing also, so I basically want to loop until a curl request to the winrm endpoint responds with a certain string.

My problems:
1. If the node doesnt respond, there simply isnt any output. When this is the case, it looks like Ansible isn't able to evaluate "result.stdout.find("some string") since result doesnt have a stdout attribute. I've been able to get around by using some bash conditonals that basically output "nothing returned" if the curl call returns empty.
2. Ansible seems to just hang there indefinetely if it cannot reach the url. This should cause my shell script to just output "nothing returned" (which I've verified manually using shell).
3. Although I have set ignore_errors to true, the script originally failed. I used the shell "|| true" to have curl always report success, although I don't think I should have to. Ansible bug?

I'm running on the latest devel commit in v1 mode.

Any pointers would be greatly appreciated. Here's the task file from the role:


- name: Wait for windows reboot
#  when: pending_reboot_output.pending_reboot == true
  shell: 'if [[ -n $(curl -s -f -k --header "Content-Type: application/soap+xml;charset=UTF-8" --header "WSMANIDENTIFY: unauthenticated" https://thansiblewin01.ansib.le:5986/wsman --data "<s:Envelope xmlns:s=http://www.w3.org/2003/05/soap-envelope xmlns:wsmid=http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd><s:Header/><s:Body><wsmid:Identify/></s:Body></s:Envelope>" || true) ]]; then curl -s -f -k --header "Content-Type: application/soap+xml;charset=UTF-8" --header "WSMANIDENTIFY: unauthenticated" https://thansiblewin01.ansib.le:5986/wsman --data "<s:Envelope xmlns:s=http://www.w3.org/2003/05/soap-envelope xmlns:wsmid=http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd><s:Header/><s:Body><wsmid:Identify/></s:Body></s:Envelope>" || true ;else echo "nothing returned" ;fi'
  register: result2
  until: result2.stdout.find("http://www.w3.org/2003/05/soap-envelope")
  retries: 10
  delay: 10
  delegate_to: 127.0.0.1
  ignore_errors: yes
  changed_when: False



Brian Coca

unread,
Jul 28, 2015, 3:26:25 PM7/28/15
to Ansible Project
have you looked at using the existing wait_for module? it should be
able to detect if the winrm port is open.


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages