Debian Codegraph @

test/integration/targets/connection_ssh/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -ux
4
5 # We skip this whole section if the test node doesn't have sshpass on it.
6 if command -v sshpass > /dev/null; then
7 # Check if our sshpass supports -P
8 sshpass -P foo > /dev/null
9 sshpass_supports_prompt=$?
10 if [[ $sshpass_supports_prompt -eq 0 ]]; then
11 # If the prompt is wrong, we'll end up hanging (due to sshpass hanging).
12 # We should probably do something better here, like timing out in Ansible,
13 # but this has been the behavior for a long time, before we supported custom
14 # password prompts.
15 #
16 # So we search for a custom password prompt that is clearly wrong and call
17 # ansible with timeout. If we time out, our custom prompt was successfully
18 # searched for. It's a weird way of doing things, but it does ensure
19 # that the flag gets passed to sshpass.
20 ../test_utils/scripts/timeout.py 5 -- ansible -m ping \
21 -e ansible_connection=ssh \
22 -e ansible_ssh_password_mechanism=sshpass \
23 -e ansible_sshpass_prompt=notThis: \
24 -e ansible_password=foo \
25 -e ansible_user=definitelynotroot \
26 -i test_connection.inventory \
27 ssh-pipelining
28 ret=$?
29 # 124 is EXIT_TIMEDOUT from gnu coreutils
30 # 143 is 128+SIGTERM(15) from BusyBox
31 if [[ $ret -ne 124 && $ret -ne 143 ]]; then
32 echo "Expected to time out and we did not. Exiting with failure."
33 exit 1
34 fi
35 else
36 ansible -m ping \
37 -e ansible_connection=ssh \
38 -e ansible_ssh_password_mechanism=sshpass \
39 -e ansible_sshpass_prompt=notThis: \
40 -e ansible_password=foo \
41 -e ansible_user=definitelynotroot \
42 -i test_connection.inventory \
43 ssh-pipelining | grep 'customized password prompts'
44 ret=$?
45 [[ $ret -eq 0 ]] || exit $ret
46 fi
47 fi
48
49 set -e
50
51 if [[ "$(scp -O 2>&1)" == "usage: scp "* ]]; then
52 # scp supports the -O option (and thus the -T option as well)
53 # work-around required
54 # see: https://www.openssh.com/txt/release-9.0
55 scp_args=("-e" "ansible_scp_extra_args=-TO")
56 elif [[ "$(scp -T 2>&1)" == "usage: scp "* ]]; then
57 # scp supports the -T option
58 # work-around required
59 # see: https://github.com/ansible/ansible/issues/52640
60 scp_args=("-e" "ansible_scp_extra_args=-T")
61 else
62 # scp does not support the -T or -O options
63 # no work-around required
64 # however we need to put something in the array to keep older versions of bash happy
65 scp_args=("-e" "")
66 fi
67
68 # sftp
69 ./posix.sh "$@"
70 # scp
71 ANSIBLE_SSH_TRANSFER_METHOD=scp ./posix.sh "$@" "${scp_args[@]}"
72 # piped
73 ANSIBLE_SSH_TRANSFER_METHOD=piped ./posix.sh "$@"
74
75 # test config defaults override
76 ansible-playbook check_ssh_defaults.yml "$@" -i test_connection.inventory
77
78 # ensure we can load from ini cfg
79 ANSIBLE_CONFIG=./test_ssh_defaults.cfg ansible-playbook verify_config.yml "$@"
80
81 # ensure we handle cp with spaces correctly, otherwise would fail with
82 # `"Failed to connect to the host via ssh: command-line line 0: keyword controlpath extra arguments at end of line"`
83 ANSIBLE_SSH_CONTROL_PATH='/tmp/ssh cp with spaces' ansible -m ping all -e ansible_connection=ssh -i test_connection.inventory "$@"
84
85 # ensure malformed ssh args fail the task with ssh's own error instead of crashing the worker
86 ansible -m ping all -e ansible_connection=ssh -e '{"ansible_ssh_extra_args": "-o ServerAliveInterval=30 -o"}' -i test_connection.inventory "$@" 2>&1 \
87 | grep 'Failed to connect to the host via ssh: command-line line 0: no argument after keyword'
88
89 # Test that timeout on waiting on become is an unreachable error
90 ansible-playbook test_unreachable_become_timeout.yml "$@"
91
92 ANSIBLE_ROLES_PATH=../ ansible-playbook "$@" -i ../../inventory test_ssh_askpass.yml
93
94 # ensure that SSH client verbosity is independent of Ansible verbosity - no `debugN:` lines at high Ansible verbosity
95 ansible ssh -m raw -a whoami -i test_connection.inventory -vvvvv | grep -v 'debug.:'
96
97 # enable SSH client verbosity level 1 via env; ensure debugN: but no debug2 or debug3 lines
98 ANSIBLE_SSH_VERBOSITY=1 ansible ssh -m raw -a whoami -i test_connection.inventory -vvvvv | grep 'debug.:' | grep -v 'debug(2|3):'
99
100 # enable SSH client verbosity level 3 via var; ensure debug3 lines
101 ansible ssh -m raw -a whoami -i test_connection.inventory -vvvvv -e ansible_ssh_verbosity=3 2>&1 | grep 'debug3:'
102
103 ansible-playbook test_escalation_check.yml "$@"
104
105 echo PASS