Trond Hindenes
2015-07-28 13:56:00 UTC
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
prettier copy at: https://gist.github.com/trondhindenes/23137e66f8a34603b8cf
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
prettier copy at: https://gist.github.com/trondhindenes/23137e66f8a34603b8cf
--
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-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f5d5e19d-641b-463b-968d-571e7beaab5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f5d5e19d-641b-463b-968d-571e7beaab5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.