Skip to content
Snippets Groups Projects
Commit 06d28e96 authored by ale's avatar ale
Browse files

Make floatup install the vagrant insecure SSH key

parent 32d1bc1d
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,37 @@ import subprocess ...@@ -12,6 +12,37 @@ import subprocess
import yaml import yaml
# The Vagrant "insecure" SSH key that is used to log onto the VMs.
INSECURE_PRIVATE_KEY = '''-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd
ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1
Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf
TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK
iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A
sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf
4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP
cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk
EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN
CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX
3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG
YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj
3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+
dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz
6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC
P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF
llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ
kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
-----END RSA PRIVATE KEY-----
'''
def parse_inventory(path, host_attrs): def parse_inventory(path, host_attrs):
with open(path) as fd: with open(path) as fd:
inventory = yaml.safe_load(fd) inventory = yaml.safe_load(fd)
...@@ -35,7 +66,7 @@ def do_request(url, ssh_gw, payload): ...@@ -35,7 +66,7 @@ def do_request(url, ssh_gw, payload):
shlex.quote(data), url) shlex.quote(data), url)
if ssh_gw: if ssh_gw:
cmd = "ssh %s %s" % (ssh_gw, shlex.quote(cmd)) cmd = "ssh %s %s" % (ssh_gw, shlex.quote(cmd))
print(f'running: {cmd}')
output = subprocess.check_output(cmd, shell=True) output = subprocess.check_output(cmd, shell=True)
try: try:
return json.loads(output) return json.loads(output)
...@@ -44,6 +75,18 @@ def do_request(url, ssh_gw, payload): ...@@ -44,6 +75,18 @@ def do_request(url, ssh_gw, payload):
raise raise
def install_ssh_key():
# Install the SSH key as Vagrant would do, for compatibility.
key_path = os.path.join(
os.getenv('HOME'), '.vagrant.d', 'insecure_private_key')
if os.path.exists(key_path):
return
os.makedirs(os.path.dirname(key_path), mode=0o700, exist_ok=True)
with open(key_path, 'w') as fd:
fd.write(INSECURE_PRIVATE_KEY)
os.chmod(key_path, 0o600)
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
...@@ -86,6 +129,8 @@ def main(): ...@@ -86,6 +129,8 @@ def main():
with open(args.state_file, 'w') as fd: with open(args.state_file, 'w') as fd:
fd.write(resp['group_id']) fd.write(resp['group_id'])
install_ssh_key()
elif args.cmd == 'down': elif args.cmd == 'down':
try: try:
with open(args.state_file) as fd: with open(args.state_file) as fd:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment