mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Reformat everything.
This commit is contained in:
@@ -84,30 +84,32 @@ from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
USER_AGENT = 'ansible-ipinfoio-module/0.0.1'
|
||||
USER_AGENT = "ansible-ipinfoio-module/0.0.1"
|
||||
|
||||
|
||||
class IpinfoioFacts:
|
||||
|
||||
def __init__(self, module):
|
||||
self.url = 'https://ipinfo.io/json'
|
||||
self.timeout = module.params.get('timeout')
|
||||
self.url = "https://ipinfo.io/json"
|
||||
self.timeout = module.params.get("timeout")
|
||||
self.module = module
|
||||
|
||||
def get_geo_data(self):
|
||||
response, info = fetch_url(self.module, self.url, force=True, # NOQA
|
||||
timeout=self.timeout)
|
||||
response, info = fetch_url(
|
||||
self.module,
|
||||
self.url,
|
||||
force=True, # NOQA
|
||||
timeout=self.timeout,
|
||||
)
|
||||
try:
|
||||
info['status'] == 200
|
||||
info["status"] == 200
|
||||
except AssertionError:
|
||||
self.module.fail_json(msg=f'Could not get {self.url} page, check for connectivity!')
|
||||
self.module.fail_json(msg=f"Could not get {self.url} page, check for connectivity!")
|
||||
else:
|
||||
try:
|
||||
content = response.read()
|
||||
result = self.module.from_json(content.decode('utf8'))
|
||||
result = self.module.from_json(content.decode("utf8"))
|
||||
except ValueError:
|
||||
self.module.fail_json(
|
||||
msg=f'Failed to parse the ipinfo.io response: {self.url} {content}')
|
||||
self.module.fail_json(msg=f"Failed to parse the ipinfo.io response: {self.url} {content}")
|
||||
else:
|
||||
return result
|
||||
|
||||
@@ -116,16 +118,15 @@ def main():
|
||||
module = AnsibleModule( # NOQA
|
||||
argument_spec=dict(
|
||||
http_agent=dict(default=USER_AGENT),
|
||||
timeout=dict(type='int', default=10),
|
||||
timeout=dict(type="int", default=10),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
ipinfoio = IpinfoioFacts(module)
|
||||
ipinfoio_result = dict(
|
||||
changed=False, ansible_facts=ipinfoio.get_geo_data())
|
||||
ipinfoio_result = dict(changed=False, ansible_facts=ipinfoio.get_geo_data())
|
||||
module.exit_json(**ipinfoio_result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user