
    Vh                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ dZ G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: ipinfoio_facts
short_description: Retrieve IP geolocation facts of a host's IP address
description:
  - Gather IP geolocation facts of a host's IP address using ipinfo.io API.
author: "Aleksei Kostiuk (@akostyuk)"
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.facts
  - community.general.attributes.facts_module
options:
  timeout:
    description:
      - HTTP connection timeout in seconds.
    required: false
    default: 10
    type: int
  http_agent:
    description:
      - Set http user agent.
    required: false
    default: "ansible-ipinfoio-module/0.0.1"
    type: str
notes:
  - Check U(http://ipinfo.io/) for more information.
zx
# Retrieve geolocation data of a host's IP address
- name: Get IP geolocation data
  community.general.ipinfoio_facts:
a  
ansible_facts:
  description: "Dictionary of IP geolocation facts for a host's IP address."
  returned: changed
  type: complex
  contains:
    ip:
      description: "Public IP address of a host."
      type: str
      sample: "8.8.8.8"
    hostname:
      description: Domain name.
      type: str
      sample: "google-public-dns-a.google.com"
    country:
      description: ISO 3166-1 alpha-2 country code.
      type: str
      sample: "US"
    region:
      description: State or province name.
      type: str
      sample: "California"
    city:
      description: City name.
      type: str
      sample: "Mountain View"
    loc:
      description: Latitude and Longitude of the location.
      type: str
      sample: "37.3860,-122.0838"
    org:
      description: "Organization's name."
      type: str
      sample: "AS3356 Level 3 Communications, Inc."
    postal:
      description: Postal code.
      type: str
      sample: "94035"
)AnsibleModule)	fetch_urlzansible-ipinfoio-module/0.0.1c                       e Zd Zd Zd Zy)IpinfoioFactsc                 `    d| _         |j                  j                  d      | _        || _        y )Nzhttps://ipinfo.io/jsontimeout)urlparamsgetr   module)selfr   s     t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipinfoio_facts.py__init__zIpinfoioFacts.__init__^   s&    +}}((3    c                     t        | j                  | j                  d| j                        \  }}	 |d   dk(   	 |j	                         }| j                  j                  |j                  d            }|S # t        $ r9 | j                  j                  dj                  | j                               Y y w xY w# t        $ r8 | j                  j                  dj                  | j                               Y y w xY w)	NT)forcer   status   utf8z/Failed to parse the ipinfo.io response: {0} {1})msgz/Could not get {0} page, check for connectivity!)r   r   r   r   read	from_jsondecode
ValueError	fail_jsonformatAssertionError)r   responseinfocontentresults        r   get_geo_datazIpinfoioFacts.get_geo_datac   s    "4;;+/<<9$	Nc!
"--/..w~~f/EF   9%%$fTXXw7 & 99  	NKK!! '<<BF488<L " N	Ns"   B< :A7 7?B98B9<>C=<C=N)__name__
__module____qualname__r   r%    r   r   r	   r	   \   s    
r   r	   c            	          t        t        t        t              t        dd            d      } t        |       }t        d|j	                         	      } | j
                  d
i | y )N)defaultint
   )typer+   )
http_agentr   T)argument_specsupports_check_modeF)changedansible_factsr)   )r   dict
USER_AGENTr	   r%   	exit_json)r   ipinfoioipinfoio_results      r   mainr9   w   sb    J/eR0
 !F V$HX%:%:%<>OF''r   __main__N)
__future__r   r   r   r.   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   ansible.module_utils.urlsr   r5   objectr	   r9   r&   r)   r   r   <module>rC      s]    A @6&
N 5 / -
F 6( zF r   