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.6.1).
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 |
|---|---|
http_agent string | Set HTTP user agent. Default: |
ip string | IP address to retrieve geolocation information. |
timeout integer | HTTP connection timeout in seconds. Default: |
Attributes
Attribute | Support | Description |
|---|---|---|
check_mode | Support: full This action does not modify state. | Can run in |
diff_mode | 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 |
|---|---|
as string | Autonomous system (AS) name. Returned: success Sample: |
asn string | Autonomous system number (ASN). Returned: success Sample: |
city_name string | City name. Returned: success Sample: |
country_code string | ISO 3166-1 alpha-2 country code. Returned: success Sample: |
country_name string | Country name based on ISO 3166. Returned: success Sample: |
ip string | Public IP address of a host. Returned: success Sample: |
is_proxy boolean | Whether is a proxy or not. Returned: success Sample: |
latitude float | Latitude of the city. Returned: success Sample: |
longitude float | Longitude of the city. Returned: success Sample: |
region_name string | State or province name. Returned: success Sample: |
time_zone string | UTC time zone (with DST supported). Returned: success Sample: |
zip_code string | ZIP/Postal code. Returned: success Sample: |
Collection links
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/projects/ansible/latest/collections/community/general/ip2location_info_module.html