<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ssh(lancet, print_cmd, environment):
 """ SSH into the given environment, based on the dploi configuration. """

    namespace = {}

    with open(lancet.config.get('dploi', 'deployment_spec')) as fh:
        code = compile(fh.read(), 'deployment.py', 'exec')
        exec(code, {}, namespace)

    config = namespace['settings'][environment]
    host = '{}@{}'.format(config['user'], config['hosts'][0])
    cmd = ['ssh', '-p', str(config.get('port', 22)), host]

    if print_cmd:
        click.echo(' '.join(quote(s) for s in cmd))
    else:
        lancet.defer_to_shell(*cmd)