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