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 © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion