Skip to content

Configure Postgres

Configure Postgres #11

Workflow file for this run

name: Configure Postgres
on:
workflow_call:
secrets:
SSH_DEVOPS_KEY_PRIVATE:
required: true
workflow_dispatch:
inputs:
docker_network:
type: string
required: true
default: traefik_network
TARGET_HOST:
type: string
required: true
SSH_PORT:
type: string
required: false
default: 22
SSH_USER:
type: string
required: false
default: "root"
SSH_USER_HOME_DIR:
type: string
required: false
default: "/root"
ANSIBLE_BECOME_PASS:
type: string
required: false
default: "no-password"
adminer_domain:
type: string
required: true
postgres_db:
type: string
required: false
default: postgres
postgres_password:
type: string
required: false
default: postgres
postgres_user:
type: string
required: false
default: postgres
jobs:
ansible:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Add SSH Keys
run: |
cat << EOF > devops-key
${{ secrets.SSH_DEVOPS_KEY_PRIVATE }}
EOF
- name: Update devops private key permissions
run: |
chmod 400 devops-key
- name: Install Ansible
run: |
pip install ansible
- name: Adding or Override Ansible inventory File
run: |
cat << EOF > ./inventory.ini
[webservers]
${{ inputs.TARGET_HOST }}
EOF
- name: Adding or Override Ansible Config File
run: |
cat << EOF > ./ansible.cfg
[defaults]
ansible_python_interpreter='/usr/bin/python3'
deprecation_warnings=False
inventory=./inventory.ini
remote_user="${{ inputs.SSH_USER }}"
remote_tmp="${{ inputs.SSH_USER_HOME_DIR }}/.ansible/tmp"
host_key_checking=False
private_key_file = ./devops-key
retries=2
EOF
- name: Adding Ansible Variables
run: |
mkdir -p psql-install/vars/
cat << EOF > psql-install/vars/main.yaml
---
docker_network: ${{ inputs.docker_network }}
adminer_domain: ${{ inputs.adminer_domain }}
postgres_password: ${{ inputs.postgres_password }}
postgres_user: ${{ inputs.postgres_user }}
postgres_db: ${{ inputs.postgres_db }}
user_home_dir: ${{ inputs.SSH_USER_HOME_DIR }}
EOF
- name: Run main playbook
run: |
if [ "${{ inputs.ANSIBLE_BECOME_PASS }}" != "no-password" ]; then
ANSIBLE_CONFIG=ansible.cfg ansible-playbook --ask-become-pass main.yml
else
ANSIBLE_CONFIG=ansible.cfg ansible-playbook main.yml
fi