-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_ssh.yml
51 lines (43 loc) · 1.13 KB
/
git_ssh.yml
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
---
- hosts: localhost
become: yes
tasks:
- name: Install git
apt:
name: git
state: present
- name: Check if SSH key already exists
stat:
path: "~/.ssh/git_id_ed25519"
register: ssh_key_check
- name: Generate SSH key
command:
cmd: ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/git_id_ed25519 -N ""
when: not ssh_key_check.stat.exists
- name: Display public key
command:
cmd: cat ~/.ssh/git_id_ed25519.pub
register: pub_key
changed_when: false
when: not ssh_key_check.stat.exists
- debug:
var: pub_key.stdout
verbosity: 1
- name: Start ssh-agent, add key, and list identities
shell: |
eval $(ssh-agent -s)
ssh-add ~/.ssh/git_id_ed25519
ssh-add -l
register: ssh_agent_output
changed_when: false
- debug:
var: ssh_agent_output.stdout_lines
verbosity: 1
- debug:
var: added_keys.stdout_lines
verbosity: 1
- name: Source .bashrc for root
shell: |
source /root/.bashrc
args:
executable: /bin/bash