-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb_cluster.yml
56 lines (47 loc) · 1.54 KB
/
db_cluster.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
52
53
54
55
56
---
- name: Configure Backup VM
import_playbook: backup.yml
- name: Configure Database VM
import_playbook: database.yml
- name: Configure Replica VM
import_playbook: replica.yml
- name: Exchange Keys between servers
become: yes
become_user: postgres
hosts: database
tasks:
- name: SSH KeyGen command
shell: >
ssh-keygen -q -b 2048 -t rsa -N "" -C "creating SSH" -f ~/.ssh/id_rsa
creates="~/.ssh/id_rsa"
- name: Fetch SSH public key
slurp:
src: ~/.ssh/id_rsa.pub
register: public_key
- name: Add SSH public key to authorized keys on target server
authorized_key:
user: postgres
state: present
key: "{{ public_key.content | b64decode }}"
delegate_to: "{{ item.dest }}"
with_items:
- { dest: "{{ groups['replica'][0] }}" }
- { dest: "{{ groups['backup'][0] }}" }
- name: Retrieve SSH fingerprints of backup VM
command: "ssh-keyscan -H {{ groups['backup'][0] }}"
register: ssh_fingerprints
- name: Add SSH fingerprints to known_hosts file
lineinfile:
path: ~/.ssh/known_hosts
line: "{{ item }}"
create: yes
loop: "{{ ssh_fingerprints.stdout_lines }}"
- name: Retrieve SSH fingerprints of replica VM
command: "ssh-keyscan -H {{ groups['replica'][0] }}"
register: ssh_fingerprints
- name: Add SSH fingerprints to known_hosts file
lineinfile:
path: ~/.ssh/known_hosts
line: "{{ item }}"
create: yes
loop: "{{ ssh_fingerprints.stdout_lines }}"