Debian Codegraph @

test/integration/targets/connection_ssh/test_ssh_askpass.yml

raw
1 - hosts: all
2 tasks:
3 - import_role:
4 role: setup_test_user
5
6 # macos currently allows password auth, and macos/15.3 prevents restarting sshd
7 - when: ansible_facts.system != 'Darwin'
8 block:
9 - find:
10 paths: /etc/ssh
11 recurse: true
12 contains: 'PasswordAuthentication'
13 register: sshd_confs
14
15 - lineinfile:
16 path: '{{ item }}'
17 regexp: '^PasswordAuthentication'
18 line: PasswordAuthentication yes
19 loop: '{{ sshd_confs.files|default([{"path": "/etc/ssh/sshd_config"}], true)|map(attribute="path") }}'
20
21 - service:
22 name: ssh{{ '' if ansible_facts.os_family == 'Debian' else 'd' }}
23 state: restarted
24 when: ansible_facts.system != 'Darwin'
25
26 - name: Test incorrect password
27 command:
28 argv:
29 - ansible
30 - localhost
31 - -m
32 - command
33 - -a
34 - id
35 - -vvv
36 - -e
37 - ansible_pipelining=yes
38 - -e
39 - ansible_connection=ssh
40 - -e
41 - ansible_ssh_password_mechanism=ssh_askpass
42 - -e
43 - ansible_user={{ test_user_name }}
44 - -e
45 - ansible_password=INCORRECT_PASSWORD
46 environment:
47 ANSIBLE_NOCOLOR: "1"
48 ANSIBLE_FORCE_COLOR: "0"
49 register: askpass_out
50 ignore_errors: true
51
52 - assert:
53 that:
54 - askpass_out is failed
55 - askpass_out.stdout is contains('UNREACHABLE')
56 - askpass_out.stdout is contains('Permission denied')
57 - askpass_out.stdout is not contains('Permission denied, please try again.') # password tried only once
58 - askpass_out.stdout is not contains('Traceback (most recent call last)')
59
60 - name: Test correct password
61 command:
62 argv:
63 - ansible
64 - localhost
65 - -m
66 - command
67 - -a
68 - id
69 - -vvv
70 - -e
71 - ansible_pipelining=yes
72 - -e
73 - ansible_connection=ssh
74 - -e
75 - ansible_ssh_password_mechanism=ssh_askpass
76 - -e
77 - ansible_user={{ test_user_name }}
78 - -e
79 - ansible_password={{ test_user_plaintext_password }}
80 environment:
81 ANSIBLE_NOCOLOR: "1"
82 ANSIBLE_FORCE_COLOR: "0"
83 register: askpass_out
84
85 - debug:
86 var: askpass_out
87
88 - assert:
89 that:
90 - '"EXEC ssh " in askpass_out.stdout'
91 - '"sshpass" not in askpass_out.stdout'
92 - askpass_out.stdout is search('uid=\d+\(' ~ test_user_name ~ '\)')