Commit 006dee6b by John Jarvis

Merge pull request #844 from edx/jarv/bastion-ssh-config

create alias for bastion
parents f064db8f bb69502a
...@@ -21,27 +21,35 @@ VERSION="vpc tools 0.1" ...@@ -21,27 +21,35 @@ VERSION="vpc tools 0.1"
DEFAULT_USER="ubuntu" DEFAULT_USER="ubuntu"
DEFAULT_HOST_CHECK="ask" DEFAULT_HOST_CHECK="ask"
JUMPBOX_CONFIG = """ BASTION_CONFIG = """Host {jump_box}
Host {jump_box} HostName {ip}
HostName {ip} ForwardAgent yes
ForwardAgent yes User {user}
User {user} StrictHostKeyChecking {strict_host_check}
StrictHostKeyChecking {strict_host_check} {identity_line}
{identity_line}
""" """
HOST_CONFIG = """ HOST_CONFIG = """# Instance ID: {instance_id}
# Instance ID: {instance_id} Host {name}
Host {name} ProxyCommand ssh {config_file} -W %h:%p {jump_box}
ProxyCommand ssh {config_file} -W %h:%p {jump_box} HostName {ip}
HostName {ip} ForwardAgent yes
ForwardAgent yes User {user}
User {user} StrictHostKeyChecking {strict_host_check}
StrictHostKeyChecking {strict_host_check} {identity_line}
{identity_line} """
BASTION_HOST_CONFIG = """# Instance ID: {instance_id}
Host {name}
HostName {ip}
ForwardAgent yes
User {user}
StrictHostKeyChecking {strict_host_check}
{identity_line}
""" """
def dispatch(args): def dispatch(args):
if args.get("ssh-config"): if args.get("ssh-config"):
...@@ -80,7 +88,7 @@ def _ssh_config(args): ...@@ -80,7 +88,7 @@ def _ssh_config(args):
else: else:
config_file = "" config_file = ""
jump_box = "{stack_name}-jumpbox".format(stack_name=stack_name) 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)
...@@ -105,39 +113,61 @@ def _ssh_config(args): ...@@ -105,39 +113,61 @@ def _ssh_config(args):
if logical_id == "BastionHost" or logical_id == 'bastion': if logical_id == "BastionHost" or logical_id == 'bastion':
print JUMPBOX_CONFIG.format( print BASTION_CONFIG.format(
jump_box=jump_box, jump_box=jump_box,
ip=instance.ip_address, ip=instance.ip_address,
user=user, user=user,
strict_host_check=strict_host_check, strict_host_check=strict_host_check,
identity_line=identity_line) identity_line=identity_line)
# Print host config even for the bastion box because that is how print BASTION_HOST_CONFIG.format(
# ansible accesses it. name=instance.private_ip_address,
print HOST_CONFIG.format( ip=instance.ip_address,
name=instance.private_ip_address, user=user,
jump_box=jump_box, instance_id=instance.id,
ip=instance.private_ip_address, strict_host_check=strict_host_check,
user=user, identity_line=identity_line)
config_file=config_file,
strict_host_check=strict_host_check, #duplicating for convenience with ansible
instance_id=instance.id, name = friendly.format(stack_name=stack_name,
identity_line=identity_line) logical_id=logical_id,
instance_number=instance_number)
#duplicating for convenience with ansible
name = friendly.format(stack_name=stack_name, print BASTION_HOST_CONFIG.format(
logical_id=logical_id, name=name,
instance_number=instance_number) ip=instance.ip_address,
user=user,
print HOST_CONFIG.format( strict_host_check=strict_host_check,
name=name, instance_id=instance.id,
jump_box=jump_box, identity_line=identity_line)
ip=instance.private_ip_address,
user=user, else:
config_file=config_file, # Print host config even for the bastion box because that is how
strict_host_check=strict_host_check, # ansible accesses it.
instance_id=instance.id, print HOST_CONFIG.format(
identity_line=identity_line) 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