1- - name : Generate SSH Keypair on Backup Server
2- hosts : backup
3- tags : backup
4- become : yes
5- vars :
6- ssh_key_path : /home/backup/.ssh/id_ed25519
7- tasks :
8- - name : Ensure .ssh directory exists
9- file :
10- path : /home/backup/.ssh
11- state : directory
12- mode : 0700
13- owner : backup
14- group : backup
1+ - name : Ensure .ssh directory exists
2+ file :
3+ path : /home/backup/.ssh
4+ state : directory
5+ mode : 0700
6+ owner : backup
7+ group : backup
158
16- - name : Generate an ed25519 SSH keypair for backup user if not present
17- openssh_keypair :
18- path : " {{ ssh_key_path }}"
19- type : ed25519
20- owner : backup
21- group : backup
22- mode : ' 0600'
23- force : false
9+ - name : Generate an ed25519 SSH keypair for backup user if not present
10+ openssh_keypair :
11+ path : " {{ backup_ssh_key_path }}"
12+ type : ed25519
13+ owner : backup
14+ group : backup
15+ mode : ' 0600'
16+ force : false
2417
25- - name : Set permissions for authorized_keys
26- file :
27- path : /home/backup/.ssh/authorized_keys
28- owner : backup
29- group : backup
30- mode : 0600
31- state : touch
18+ - name : Set permissions for authorized_keys
19+ file :
20+ path : /home/backup/.ssh/authorized_keys
21+ owner : backup
22+ group : backup
23+ mode : 0600
24+ state : touch
3225
33- - name : Add public key to authorized_keys
34- ansible.builtin.lineinfile :
35- path : /home/backup/.ssh/authorized_keys
36- line : " {{ lookup('file', ssh_key_path + '.pub') }}"
37- create : yes
38- owner : backup
39- group : backup
40- mode : 0600
41- when : ssh_key_path is defined
26+ - name : Add public key to authorized_keys
27+ ansible.builtin.lineinfile :
28+ path : /home/backup/.ssh/authorized_keys
29+ line : " {{ lookup('file', backup_ssh_key_path + '.pub') }}"
30+ create : yes
31+ owner : backup
32+ group : backup
33+ mode : 0600
34+ when : backup_ssh_key_path is defined
4235
43- - name : Copy private key from backup server to control node
44- fetch :
45- src : " {{ ssh_key_path }}"
46- dest : " ./id_ed25519_backup"
47- flat : yes
48- mode : ' 0600'
49-
50- - name : Create Kubernetes Secret for backup SSH key
51- hosts : master
52- gather_facts : no
53- tags : backup
54- tasks :
55- - name : Create the kube secret using local kubectl
56- # FIXME: remove hardcoded namespace
57- ansible.builtin.command : >
58- kubectl create secret generic backup-ssh-key --namespace opencrvs-demo
59- --from-file=id_ed25519=./id_ed25519_backup
60- args :
61- removes : backup-ssh-key
62- # If you want this to update the secret if it already exists, use kubectl apply or kubectl delete/create
63- register : kubectl_output
64- ignore_errors : true
65-
66- - name : Print kubectl output
67- debug :
68- var : kubectl_output.stdout
36+ - name : Copy private key from backup server to control node
37+ fetch :
38+ src : " {{ backup_ssh_key_path }}"
39+ dest : " ./id_ed25519_backup"
40+ flat : yes
41+ mode : ' 0600'
0 commit comments