Get public facing IP of remote machine

Published: 2018-07-10 09:36:42 +0000
Categories: Ansible,




On occasion, you might need to identify the IP address of the machine being ansibled. However, there are various scenarios (AWS instances, alicloud instances, NAT etc) where the public facing IP of your machine may not necessarily be bound directly to an interface on the system you're running ansible against.

This simple role places a call out to a Web based endpoint and sets a fact based upon the response so that you can use it later (for example to whitelist it in firewall rules on another machine).


- name: Get System Public IP
      return_content: yes
  register: ip_lookup
- set_fact:
      system_ip: "{{ ip_lookup.content | regex_replace('\n','') }}"




ansible, IP, machine, facts, variables, IP Address, Address,

Latest Posts

Urldecode string (LUA)
FFMPEG Convert YUV444p to YUV420p (BASH)
Forcing FFMPEG to honour segment length in HLS Stream Creator (BASH)
Force CURL to place request to a specific IP (BASH)
Set a variable only if it is undefined (Javascript)
Ignore query string with Nginx caching proxy (NGinx)
Get breakdown of UK and non-UK votes for a Parliamentary Petition (Python)
Decompress Mozilla Firefox jsonlz4 bookmark backup files (Python)
Setting Git author details for a single repo (Git)
Checking Virtual Machine Resource Allocations with Libvirt (BASH)

Copyright © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at and snippets.6zdgh5a5e6zpchdz.onion