Get public facing IP of remote machine



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

Language

Ansible

Description

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).

Snippet

- name: Get System Public IP
  uri:
      url: http://checkip.amazonaws.com/
      return_content: yes
  register: ip_lookup
- set_fact:
      system_ip: "{{ ip_lookup.content | regex_replace('\n','') }}"

License

BSD-3-Clause

Keywords

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

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter