
    Vh                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZ  G d	 d
e      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionuN  
module: ipify_facts
short_description: Retrieve the public IP of your internet gateway
description:
  - If behind NAT and need to know the public IP of your internet gateway.
author:
  - René Moser (@resmo)
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.facts
  - community.general.attributes.facts_module
options:
  api_url:
    description:
      - URL of the ipify.org API service.
      - C(?format=json) will be appended per default.
    type: str
    default: https://api.ipify.org/
  timeout:
    description:
      - HTTP connection timeout in seconds.
    type: int
    default: 10
  validate_certs:
    description:
      - When set to V(false), SSL certificates will not be validated.
    type: bool
    default: true
notes:
  - Visit https://www.ipify.org to get more information.
a  
# Gather IP facts from ipify.org
- name: Get my public IP
  community.general.ipify_facts:

# Gather IP facts from your own ipify service endpoint with a custom timeout
- name: Get my public IP
  community.general.ipify_facts:
    api_url: http://api.example.com/ipify
    timeout: 20
zv
ipify_public_ip:
  description: Public IP of the internet gateway.
  returned: success
  type: str
  sample: 1.2.3.4
N)AnsibleModule)	fetch_url)to_textc                       e Zd Zd Zd Zy)
IpifyFactsc                     t         j                  j                  d      | _        t         j                  j                  d      | _        y )Napi_urltimeout)moduleparamsgetr   r   )selfs    q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipify_facts.py__init__zIpifyFacts.__init__I   s.    }}((3}}((3    c                 N   dd i}t        t        | j                  dz   d| j                        \  }}|s1t        j	                  d| j                  d| j                  d       t        j                  t        |j                                     }|j                  d	      |d<   |S )
Nipify_public_ipz?format=jsonT)r   urlforcer   z!No valid or no response from url z within z seconds (timeout))msgip)
r   r   r   r   	fail_jsonjsonloadsr   readr   )r   resultresponseinfodatas        r   runzIpifyFacts.runM   s    t
 %F~8U]akokwkwx4fjfrfrtx  uA  uA  "B  Czz'(--/23$(HHTN !r   N)__name__
__module____qualname__r   r#    r   r   r
   r
   G   s    4r   r
   c            
          t        t        t        dd      t        dd      t        dd            d	      at               j	                         } t        d
|       }t        j
                  di | y )Nstrzhttps://api.ipify.org/)typedefaultint
   boolT)r   r   validate_certs)argument_specsupports_check_modeF)changedansible_factsr'   )r   dictr   r
   r#   	exit_json)ipify_factsipify_facts_results     r   mainr8   [   si    e-EFeR0VT:

 !F ,""$Ke;G
*)*r   __main__)
__future__r   r   r   r*   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   ansible.module_utils.urlsr   +ansible.module_utils.common.text.convertersr   objectr
   r8   r$   r'   r   r   <module>rC      s\    A @@

  4 / ? (+  zF r   