Commit b8a05faf by Fred Smith

make jump box specifiable and overridable

parent 65d93334
"""VPC Tools. """VPC Tools.
Usage: Usage:
vpc-tools.py ssh-config (vpc <vpc_id> | stack-name <stack_name>) [(identity-file <identity_file>)] user <user> [(config-file <config_file>)] [(strict-host-check <strict_host_check>)] vpc-tools.py ssh-config (vpc <vpc_id> | stack-name <stack_name>) [(identity-file <identity_file>)] user <user> [(config-file <config_file>)] [(strict-host-check <strict_host_check>)] [(jump-box <jump_box>)]
vpc-tools.py (-h --help) vpc-tools.py (-h --help)
vpc-tools.py (-v --version) vpc-tools.py (-v --version)
...@@ -39,6 +39,16 @@ Host {name} ...@@ -39,6 +39,16 @@ Host {name}
{identity_line} {identity_line}
""" """
DIRECT_HOST_CONFIG = """# Instance ID: {instance_id}
Host {name}
HostName {ip}
ForwardAgent yes
User {user}
StrictHostKeyChecking {strict_host_check}
{identity_line}
"""
BASTION_HOST_CONFIG = """# Instance ID: {instance_id} BASTION_HOST_CONFIG = """# Instance ID: {instance_id}
Host {name} Host {name}
HostName {ip} HostName {ip}
...@@ -88,7 +98,11 @@ def _ssh_config(args): ...@@ -88,7 +98,11 @@ def _ssh_config(args):
else: else:
config_file = "" config_file = ""
jump_box = "{stack_name}-bastion".format(stack_name=stack_name) if args.get("jump-box"):
jump_box = args.get("<jump_box>")
else:
jump_box = "{stack_name}-bastion".format(stack_name=stack_name)
friendly = "{stack_name}-{logical_id}-{instance_number}" friendly = "{stack_name}-{logical_id}-{instance_number}"
id_type_counter = defaultdict(int) id_type_counter = defaultdict(int)
...@@ -144,30 +158,55 @@ def _ssh_config(args): ...@@ -144,30 +158,55 @@ def _ssh_config(args):
else: else:
# Print host config even for the bastion box because that is how # Print host config even for the bastion box because that is how
# ansible accesses it. # ansible accesses it.
print HOST_CONFIG.format( if jump_box == "none":
name=instance.private_ip_address, print DIRECT_HOST_CONFIG.format(
jump_box=jump_box, name=instance.private_ip_address,
ip=instance.private_ip_address, ip=instance.private_ip_address,
user=user, user=user,
config_file=config_file, config_file=config_file,
strict_host_check=strict_host_check, strict_host_check=strict_host_check,
instance_id=instance.id, instance_id=instance.id,
identity_line=identity_line) identity_line=identity_line)
#duplicating for convenience with ansible #duplicating for convenience with ansible
name = friendly.format(stack_name=stack_name, name = friendly.format(stack_name=stack_name,
logical_id=logical_id, logical_id=logical_id,
instance_number=instance_number) instance_number=instance_number)
print HOST_CONFIG.format( print DIRECT_HOST_CONFIG.format(
name=name, name=name,
jump_box=jump_box, ip=instance.private_ip_address,
ip=instance.private_ip_address, user=user,
user=user, config_file=config_file,
config_file=config_file, strict_host_check=strict_host_check,
strict_host_check=strict_host_check, instance_id=instance.id,
instance_id=instance.id, identity_line=identity_line)
identity_line=identity_line)
else:
print HOST_CONFIG.format(
name=instance.private_ip_address,
jump_box=jump_box,
ip=instance.private_ip_address,
user=user,
config_file=config_file,
strict_host_check=strict_host_check,
instance_id=instance.id,
identity_line=identity_line)
#duplicating for convenience with ansible
name = friendly.format(stack_name=stack_name,
logical_id=logical_id,
instance_number=instance_number)
print HOST_CONFIG.format(
name=name,
jump_box=jump_box,
ip=instance.private_ip_address,
user=user,
config_file=config_file,
strict_host_check=strict_host_check,
instance_id=instance.id,
identity_line=identity_line)
if __name__ == '__main__': if __name__ == '__main__':
args = docopt(__doc__, version=VERSION) args = docopt(__doc__, version=VERSION)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment