Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularise playbook tasks, use only one playbook for all deployment sizes #798

Merged
merged 7 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions .github/workflows/provision.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Provision environment
run-name: Provision ${{ github.event.inputs.environment }}
on:
push:
branches:
- playbook-cleanup
workflow_dispatch:
inputs:
environment:
Expand All @@ -12,10 +15,6 @@ on:
- staging
- qa
- production
branch_name:
description: Branch to provision from
default: develop
required: true

jobs:
provision:
Expand Down Expand Up @@ -112,20 +111,19 @@ jobs:
elasticsearch_superuser_password: ${{ secrets.ELASTICSEARCH_SUPERUSER_PASSWORD }}
# ansible_sudo_pass: ${{ secrets.SUDO_PASSWORD }} in case your user is not root

# TODO: Iterate for 3 or 5 replicas
- name: Create ini file for 1 replica
id: ini-file
- name: Read known hosts
run: |
touch ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
echo "[docker-manager-first]" > ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
echo "manager1 ansible_host=\"${{ secrets.SSH_HOST }}\" ansible_user=${{ secrets.SSH_USER }} ansible_ssh_private_key_file=/tmp/server.pem" >> ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
echo "" >> ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
echo "[all:vars]" >> ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
echo "data1_hostname=${{ vars.HOSTNAME }}" >> ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
cd ${{ github.event.repository.name }}
echo "KNOWN_HOSTS<<EOF" >> $GITHUB_ENV
sed -i -e '$a\' ./infrastructure/.known-hosts
cat ./infrastructure/.known-hosts >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Check ini content
run: |
cat ${{ github.event.repository.name }}/infrastructure/server-setup/replicas-1.ini
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ env.KNOWN_HOSTS }}

- name: Run playbook on 1 replica in qa
uses: dawidd6/action-ansible-playbook@v2
Expand All @@ -135,11 +133,15 @@ jobs:
ANSIBLE_SSH_TIMEOUT: 30
ANSIBLE_SSH_RETRIES: 20
with:
playbook: playbook-1.yml
playbook: playbook.yml
directory: ${{ github.event.repository.name }}/infrastructure/server-setup
inventory: |
[docker-manager-first]
${{ vars.HOSTNAME }} ansible_host="${{ secrets.SSH_HOST }}" data_label=data1

[docker-workers]
options: |
--verbose
--inventory replicas-1.ini
--extra-vars ""${{ steps.ansible-variables.outputs.EXTRA_VARS }}""

- name: Run playbook on 1 replica in production
Expand All @@ -150,9 +152,13 @@ jobs:
ANSIBLE_SSH_TIMEOUT: 30
ANSIBLE_SSH_RETRIES: 20
with:
playbook: playbook-1.yml
playbook: playbook.yml
directory: ${{ github.event.repository.name }}/infrastructure/server-setup
inventory: |
[docker-manager-first]
${{ vars.HOSTNAME }} ansible_host="${{ secrets.SSH_HOST }}" data_label=data1

[docker-workers]
options: |
--verbose
--inventory replicas-1.ini
--extra-vars ""${{ steps.ansible-production-variables.outputs.EXTRA_VARS }}""
12 changes: 12 additions & 0 deletions infrastructure/.known-hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Farajaland staging
|1|QaneIg/kW2nT73307HQ/9Y9Bz5A=|RIaMnvGPGkJFWdEJFxWc8RLFs5E= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOKbJ1oRhgHaRxj4G8k9rkqIla59c4yWUkbfxX7y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zXiJ7VGAZq1twRYGSnRTJyCja3eJfvQfxb8hGVz2fkf9rthgYABdoHSJoGMTt4EP2LtTduzvLPCBctiID6bXUFMkM6j2pmLQK/gZGEKNaJb86D7xt1HXQsqV5bAAKCaehgn6LAQ8zee9YZtoP8fwhoorTJEJ3kpsvsneEpV3kiuAPdyfB8zI7E3HHqXgD+ij0eFogK+NSUIMUexFyRZgAtKDBjnNRQLGMEzY1UzM7pojRr8Bb9vT4tGJGBpzfWvWn6WavIpBa3Ht6sXmXHGexGn2X8gyG5rHif2FAmTV7O4M+sBlpxqr7G906BJ8JwOl8qp8T9BnesWiExFdeDwzsRPS49KQOBpxOqfK5OC1ZQlEzVIR1SQpOAGjDgGM1XtR4jsBX6OBlR7hcYSw9F6wCWjrWFrmv6HVNAXZgYsnzXQmJPpDbRQAyHTvIHK9/DobQI8=
|1|FuRTlvDs4p17HjsAIGQ7wQml0TM=|qDsBKG5gV6TDM2dw0lykGLS+11M= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO/ZvINySxP0MXtHBbaJ6FqDBaFUl/YVAyUItqfiyeez
9 changes: 2 additions & 7 deletions infrastructure/server-setup/example-1.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
; Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
[docker-manager-first]
; Uncomment the line below
; manager1 ansible_host="ENTER YOUR MANAGER HOST IP"
ENTER_HOSTNAME_1 ansible_host="ENTER YOUR MANAGER HOST IP" data_label=data1

; Below you can assign 1 node to be the data node, use the node's HOSTNAME in these variables.
; These node will be used by databases to permanently store data.
; Used for Mongo replica sets
[all:vars]
; Uncomment the line below
; data1_hostname=ENTER_HOSTNAME_1
[docker-workers]
15 changes: 3 additions & 12 deletions infrastructure/server-setup/example-3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@
; Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
[docker-manager-first]
; Uncomment the line below
; manager1 ansible_host="ENTER YOUR MANAGER HOST IP"
ENTER_HOSTNAME_1 ansible_host="ENTER YOUR MANAGER HOST IP" data_label=data1

[docker-workers]
; We recommend you add 2 workers for a usual production deployment
; Uncomment the lines below
; worker1 ansible_host="ENTER YOUR WORKER 1 HOST IP"
; worker2 ansible_host="ENTER YOUR WORKER 2 HOST IP"

; Below you can assign 3 node to be data nodes, use the node's HOSTNAME in these variables.
; These node will be used by databases to permanently store data.
; Used for Mongo replica sets
[all:vars]
; Uncomment the lines below
; data1_hostname=ENTER_HOSTNAME_1
; data2_hostname=ENTER_HOSTNAME_2
; data3_hostname=ENTER_HOSTNAME_3
ENTER_HOSTNAME_2 ansible_host="ENTER YOUR WORKER HOST IP" data_label=data2
ENTER_HOSTNAME_3 ansible_host="ENTER YOUR WORKER HOST IP" data_label=data3
21 changes: 5 additions & 16 deletions infrastructure/server-setup/example-5.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
; Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
[docker-manager-first]
; Uncomment the line below
; manager1 ansible_host="ENTER YOUR MANAGER HOST IP"
ENTER_HOSTNAME_1 ansible_host="ENTER YOUR MANAGER HOST IP" data_label=data1

[docker-workers]
; We recommend you add 4 workers for a scaled production deployment
; Uncomment the lines below
; worker1 ansible_host="ENTER YOUR WORKER 1 HOST IP"
; worker2 ansible_host="ENTER YOUR WORKER 2 HOST IP"
; worker3 ansible_host="ENTER YOUR WORKER 3 HOST IP"
; worker4 ansible_host="ENTER YOUR WORKER 4 HOST IP"

; Below you can assign 5 node to be data nodes, use the node's HOSTNAME in these variables.
; These node will be used by databases to permanently store data.
; Used for Mongo replica sets
[all:vars]
; Uncomment the lines below
; data1_hostname=ENTER_HOSTNAME_1
; data2_hostname=ENTER_HOSTNAME_2
; data3_hostname=ENTER_HOSTNAME_3
; data4_hostname=ENTER_HOSTNAME_4
; data5_hostname=ENTER_HOSTNAME_5
ENTER_HOSTNAME_2 ansible_host="ENTER YOUR WORKER 1 HOST IP" data_label=data2
ENTER_HOSTNAME_3 ansible_host="ENTER YOUR WORKER 2 HOST IP" data_label=data3
ENTER_HOSTNAME_4 ansible_host="ENTER YOUR WORKER 3 HOST IP" data_label=data4
ENTER_HOSTNAME_5 ansible_host="ENTER YOUR WORKER 4 HOST IP" data_label=data5
Loading
Loading