Skip to content

Commit 7d8a59a

Browse files
committed
fix
1 parent 2b0d885 commit 7d8a59a

File tree

4 files changed

+68
-72
lines changed

4 files changed

+68
-72
lines changed

infrastructure/server-setup/group_vars/all.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ pod_network_cidr: "192.168.0.0/16"
1919
calico_version: "v3.26.1"
2020
backup_server_remote_target_directories:
2121
- /home/backup/prod
22-
- /home/backup/staging
22+
- /home/backup/staging
23+
backup_ssh_key_path: /home/backup/.ssh/id_ed25519

infrastructure/server-setup/k8s.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,3 @@
9191
tasks:
9292
- name: Run UFW
9393
include_tasks: tasks/k8s/ufw.yml
94-
- name: Additional configuration
95-
become: yes
96-
hosts: master
97-
tasks:
98-
- name: Create backup secret
99-
include_tasks: tasks/k8s/create-backup-server-secret.yml
100-
tags: backup

infrastructure/server-setup/playbook.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,32 @@
6262
- import_playbook: k8s.yml
6363

6464
- import_playbook: backup.yml
65+
66+
- name: Additional configuration
67+
become: yes
68+
hosts: backup
69+
tasks:
70+
- name: Create backup secret
71+
include_tasks: tasks/k8s/create-backup-server-secret.yml
72+
tags: backup
73+
74+
75+
- name: Create Kubernetes Secret for backup SSH key
76+
hosts: master
77+
gather_facts: no
78+
tags: backup
79+
tasks:
80+
- name: Create the kube secret using local kubectl
81+
# FIXME: remove hardcoded namespace
82+
ansible.builtin.command: >
83+
kubectl create secret generic backup-ssh-key --namespace opencrvs-demo
84+
--from-file=id_ed25519=./id_ed25519_backup
85+
args:
86+
removes: backup-ssh-key
87+
# If you want this to update the secret if it already exists, use kubectl apply or kubectl delete/create
88+
register: kubectl_output
89+
ignore_errors: true
90+
91+
- name: Print kubectl output
92+
debug:
93+
var: kubectl_output.stdout
Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,41 @@
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

Comments
 (0)