From 8de10ac1bf133c41cc1d0e330714e1659e42b092 Mon Sep 17 00:00:00 2001 From: Jonathan Math Date: Thu, 4 Feb 2021 17:42:55 -0500 Subject: [PATCH] add script to write consul-manager ip to a text file --- consul/get_consul_manager_ip.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 consul/get_consul_manager_ip.py diff --git a/consul/get_consul_manager_ip.py b/consul/get_consul_manager_ip.py new file mode 100644 index 000000000..043d0dce4 --- /dev/null +++ b/consul/get_consul_manager_ip.py @@ -0,0 +1,19 @@ + +import os +import digitalocean + +TOKEN_FILE = "/srv/secrets-newsblur/keys/digital_ocean.token" + +with open(TOKEN_FILE) as f: + token = f.read().strip() + os.environ['DO_API_TOKEN'] = token + +manager = digitalocean.Manager(token=token) +my_droplets = manager.get_all_droplets() +consul_manager_droplet = [d for d in my_droplets if d.name == "consul-manager"][0] +consul_manager_ip_address = consul_manager_droplet.ip_address + +# write or overwrite the consul-manager ip +if "consul_manager_ip.txt" not in os.listdir('ansible'): + with open('consul_manager_ip.txt', 'w') as f: + f.write(consul_manager_ip_address) \ No newline at end of file