community.general.ip2location_info module – Retrieve IP geolocation information of a host’s IP address
Note
This module is part of the community.general collection (version 12.2.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general.
To use it in a playbook, specify: community.general.ip2location_info.
New in community.general 12.2.0
Synopsis
Gather IP geolocation information of a host’s IP address using the keyless api.ip2location.io API.
Parameters
Parameter |
Comments |
|---|---|
Set HTTP user agent. Default: |
|
IP address to retrieve geolocation information. |
|
HTTP connection timeout in seconds. Default: |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full This action does not modify state. |
Can run in |
|
Support: N/A This action does not modify state. |
Returns details on what has changed (or possibly needs changing in |
Notes
Note
This module uses the keyless endpoint which has usage limits. Check https://www.ip2location.io/ip2location-documentation for more information.
Examples
# Retrieve geolocation data of a host's IP address
- name: Get IP geolocation data
community.general.ip2location_info:
register: result
- name: Show some information
ansible.builtin.debug:
msg: "{{ result.ip }} is located in {{ result.country_code }} ({{ result.country_name }})"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Dictionary of IP geolocation information for the IP address. Returned: changed |
|
Autonomous system (AS) name. Returned: success Sample: |
|
Autonomous system number (ASN). Returned: success Sample: |
|
City name. Returned: success Sample: |
|
ISO 3166-1 alpha-2 country code. Returned: success Sample: |
|
Country name based on ISO 3166. Returned: success Sample: |
|
Public IP address of a host. Returned: success Sample: |
|
Whether is a proxy or not. Returned: success Sample: |
|
Latitude of the city. Returned: success Sample: |
|
Longitude of the city. Returned: success Sample: |
|
State or province name. Returned: success Sample: |
|
UTC time zone (with DST supported). Returned: success Sample: |
|
ZIP/Postal code. Returned: success Sample: |