Debian Codegraph @

test/integration/targets/ssh_agent/tasks/tests.yml

raw
1 - slurp:
2 path: ~/.ssh/authorized_keys
3 register: akeys
4
5 - debug:
6 msg: '{{ akeys.content|b64decode }}'
7
8 - command: ansible-playbook -i {{ ansible_inventory_sources|first|quote }} -vvv {{ role_path }}/auto.yml
9 environment:
10 ANSIBLE_CALLBACK_RESULT_FORMAT: yaml
11 ANSIBLE_SSH_AGENT: auto
12 register: auto
13
14 - command: ps {{ ps_flags }} -opid
15 register: pids
16 # Some distros will exit with rc=1 if no processes were returned
17 vars:
18 ps_flags: '{{ "" if ansible_distribution == "Alpine" else "-x" }}'
19
20 - assert:
21 that:
22 - >-
23 'started and bound to' in auto.stdout
24 - >-
25 'SSH: SSH_AGENT adding' in auto.stdout
26 - >-
27 'exists in agent' in auto.stdout
28 - pids|map('trim')|select('eq', pid) == []
29 vars:
30 pid: '{{ auto.stdout|regex_findall("ssh-agent\[(\d+)\]")|first }}'
31
32 - shell: ssh-agent -D -s -a '{{ output_dir }}/agent.sock' &
33 register: ssh_agent_result
34
35 - block:
36 - command: ansible-playbook -i {{ ansible_inventory_sources|first|quote }} -vvv {{ role_path }}/auto.yml
37 environment:
38 ANSIBLE_CALLBACK_RESULT_FORMAT: yaml
39 ANSIBLE_SSH_AGENT: '{{ output_dir }}/agent.sock'
40 register: existing
41 always:
42 - command: "kill {{ ssh_agent_result.stdout | regex_search('Agent pid ([0-9]+)', '\\1') | first }}"
43
44 - assert:
45 that:
46 - >-
47 'started and bound to' not in existing.stdout
48 - >-
49 'SSH: SSH_AGENT adding' in existing.stdout
50 - >-
51 'exists in agent' in existing.stdout
52
53 - name: test various agent failure modes
54 shell: ansible localhost -m ping
55 environment:
56 ANSIBLE_SSH_AGENT: auto
57 ANSIBLE_SSH_AGENT_EXECUTABLE: "{{ role_path }}/fake_agents/ssh-agent-{{ item }}"
58 ignore_errors: true
59 register: failures
60 loop: [not-found, hangs, incompatible, truncated-early-exit, bad-shebang]
61
62 - assert:
63 that:
64 - failures.results | select('success') | length == 0
65 - failures.results[0].stderr is search 'SSH_AGENT set to auto, but cannot find ssh-agent binary'
66 - failures.results[1].stderr is search 'Timed out waiting for expected stdout .* from ssh-agent'
67 - failures.results[2].stderr is search 'The ssh-agent output .* did not match expected'
68 - failures.results[3].stderr is search 'The ssh-agent terminated prematurely'
69 - failures.results[4].stderr is search 'Could not start ssh-agent'