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

http_agent

string

Set HTTP user agent.

Default: "ansible-ip2location-info-module/0.0.1"

ip

string

IP address to retrieve geolocation information.

timeout

integer

HTTP connection timeout in seconds.

Default: 10

Attributes

Attribute

Support

Description

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Notes

Note

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

record

complex

Dictionary of IP geolocation information for the IP address.

Returned: changed

as

string

Autonomous system (AS) name.

Returned: success

Sample: "Google LLC"

asn

string

Autonomous system number (ASN).

Returned: success

Sample: "15169"

city_name

string

City name.

Returned: success

Sample: "Mountain View"

country_code

string

ISO 3166-1 alpha-2 country code.

Returned: success

Sample: "US"

country_name

string

Country name based on ISO 3166.

Returned: success

Sample: "United States of America"

ip

string

Public IP address of a host.

Returned: success

Sample: "8.8.8.8"

is_proxy

boolean

Whether is a proxy or not.

Returned: success

Sample: false

latitude

float

Latitude of the city.

Returned: success

Sample: 37.386

longitude

float

Longitude of the city.

Returned: success

Sample: -122.0838

region_name

string

State or province name.

Returned: success

Sample: "California"

time_zone

string

UTC time zone (with DST supported).

Returned: success

Sample: "-08:00"

zip_code

string

ZIP/Postal code.

Returned: success

Sample: "94035"

Authors

  • IP2Location (@ip2location)