mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add retry to ec2_metadata_facts query (#38957)
* Add retry to ec2_metadata_facts query * Fix conditional to allow for 404 errors
This commit is contained in:
parent
e79823191a
commit
9c9a70b168
1 changed files with 11 additions and 1 deletions
|
@ -420,6 +420,7 @@ ansible_facts:
|
|||
import json
|
||||
import re
|
||||
import socket
|
||||
import time
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_text
|
||||
|
@ -445,7 +446,16 @@ class Ec2Metadata(object):
|
|||
self._prefix = 'ansible_ec2_%s'
|
||||
|
||||
def _fetch(self, url):
|
||||
(response, info) = fetch_url(self.module, url, force=True)
|
||||
response, info = fetch_url(self.module, url, force=True)
|
||||
|
||||
if info.get('status') not in (200, 404):
|
||||
time.sleep(3)
|
||||
# request went bad, retry once then raise
|
||||
self.module.warn('Retrying query to metadata service. First attempt failed: {0}'.format(info['msg']))
|
||||
response, info = fetch_url(self.module, url, force=True)
|
||||
if info.get('status') not in (200, 404):
|
||||
# fail out now
|
||||
self.module.fail_json(msg='Failed to retrieve metadata from AWS: {0}'.format(info['msg']), response=info)
|
||||
if response:
|
||||
data = response.read()
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue