def test_wrap_args_with_ssh_agent_defaults(tmp_path): rc = BaseConfig(private_data_dir=str(tmp_path)) res = rc.wrap_args_with_ssh_agent(['ansible-playbook', 'main.yaml'], f'{tmp_path}/sshkey') assert res == [ 'ssh-agent', 'sh', '-c', f"trap 'rm -f {tmp_path}/sshkey' EXIT && ssh-add {tmp_path}/sshkey && rm -f {tmp_path}/sshkey && ansible-playbook main.yaml" ]
def test_wrap_args_with_ssh_agent_with_auth(): rc = BaseConfig(private_data_dir='/tmp') res = rc.wrap_args_with_ssh_agent(['ansible-playbook', 'main.yaml'], '/tmp/sshkey', '/tmp/sshauth') assert res == [ 'ssh-agent', '-a', '/tmp/sshauth', 'sh', '-c', "trap 'rm -f /tmp/sshkey' EXIT && ssh-add /tmp/sshkey && rm -f /tmp/sshkey && ansible-playbook main.yaml" ]
def test_wrap_args_with_ssh_agent_silent(): rc = BaseConfig(private_data_dir='/tmp') res = rc.wrap_args_with_ssh_agent(['ansible-playbook', 'main.yaml'], '/tmp/sshkey', silence_ssh_add=True) assert res == [ 'ssh-agent', 'sh', '-c', "trap 'rm -f /tmp/sshkey' EXIT && ssh-add /tmp/sshkey 2>/dev/null && rm -f /tmp/sshkey && ansible-playbook main.yaml" ]