-
Notifications
You must be signed in to change notification settings - Fork 9
/
hello_with_sshadd_passphrase_endpointcred.yaml
56 lines (53 loc) · 1.74 KB
/
hello_with_sshadd_passphrase_endpointcred.yaml
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
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Start ssh-agent and Retrieve the SSH_AUTH_SOCK and SSH_AGENT_PID environment variables
shell: |
eval $(ssh-agent -s) > /dev/null
echo '{"SSH_AUTH_SOCK":"'$SSH_AUTH_SOCK'","SSH_AGENT_PID":"'$SSH_AGENT_PID'"}'
register: env_vars_stdout
- set_fact:
env_vars: "{{ env_vars_stdout.stdout }}"
- name: Print the environment variables
debug:
msg: "{{ env_vars }}"
- name: Role ensures that ssh key passphrases are added to ssh-agent
hosts: localhost
connection: local
gather_facts: no
environment: "{{ env_vars }}"
roles:
- ansible-role-ssh-add-jumphosts
tasks:
- set_fact:
endpoint_ssh_private_key: "{{ lookup('env','EP_SSH_PRIVATE_KEY') }}"
- hosts: all
gather_facts: no
vars:
ansible_ssh_common_args: "{{ hostvars['127.0.0.1']['ansible_ssh_common_args'] }}"
endpoint_ssh_private_key: "{{ hostvars['127.0.0.1']['endpoint_ssh_private_key'] }}"
endpoint_ssh_user: "{{ hostvars['127.0.0.1']['endpoint_ssh_user'] }}"
endpoint_ssh_port: "{{ hostvars['127.0.0.1']['endpoint_ssh_port'] }}"
tasks:
- include_vars:
file: include_endpointcred.yaml
when:
- endpoint_ssh_private_key is defined and endpoint_ssh_private_key!=''
- endpoint_ssh_user is defined and endpoint_ssh_user!=''
- endpoint_ssh_port is defined and endpoint_ssh_port!=''
- shell: echo Hello `hostname`
register: result
- debug:
msg: "{{ result }}"
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Kill the ssh-agent
shell: |
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID
ssh-agent -k
environment: "{{ env_vars }}"