From b1de301261560e7a0430da3419649e4af64a1af0 Mon Sep 17 00:00:00 2001
From: Clark Boylan <clark.boylan@gmail.com>
Date: Tue, 30 Jul 2019 14:57:05 -0700
Subject: [PATCH] Use public_v4 addr when ignoring ipv6

In our launch node script we have the option to ignore ipv6 to deal with
clouds like ovh that report an ipv6 address but don't actually provide
that data to the instance so it cannot configure ipv6. When we ignore
ipv6 we should not try to use the ipv6 address at all.

Use the public_v4 address in this case when writing out an ansible
inventory to run the base.yaml playbook when launching the node.
Otherwise we could use ipv6 which doesn't work.

Change-Id: I2ce5cc0db9852d3426828cf88965819f88b3ebd5
---
 launch/launch-node.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/launch/launch-node.py b/launch/launch-node.py
index 2e1ae2016c..406e0741d0 100755
--- a/launch/launch-node.py
+++ b/launch/launch-node.py
@@ -160,11 +160,16 @@ def bootstrap_server(server, key, name, volume_device, keep,
             key.write_private_key(key_file)
         os.chmod(jobdir.key, 0o600)
 
+        if ignore_ipv6:
+            host_ip = server.public_v4
+        else:
+            host_ip = server.interface_ip
+
         # Write out inventory
         with open(jobdir.hosts, 'w') as inventory_file:
             inventory_file.write(
                 "{host} ansible_host={ip} ansible_user=root {python}".format(
-                    host=name, ip=server.interface_ip,
+                    host=name, ip=host_ip,
                     python='ansible_python_interpreter=/usr/bin/python3'))
 
         t = threading.Thread(target=stream_syslog, args=(ssh_client,))