57 lines
1.3 KiB
YAML
57 lines
1.3 KiB
YAML
name: Ansible
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'ansible/**'
|
|
workflow_dispatch:
|
|
inputs:
|
|
playbook:
|
|
description: 'Playbook to run'
|
|
required: true
|
|
default: 'infra.yml'
|
|
type: choice
|
|
options:
|
|
- infra.yml
|
|
|
|
jobs:
|
|
ansible:
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: ansible
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install Ansible
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get install -y ansible
|
|
|
|
- name: Write SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.DROPLET_SSH_KEY }}" > ~/.ssh/do
|
|
chmod 600 ~/.ssh/do
|
|
ssh-keyscan -H git-ssh.lunarfront.tech >> ~/.ssh/known_hosts
|
|
|
|
- name: Write inventory
|
|
run: |
|
|
echo "[infra]" > inventory.ini
|
|
echo "git-ssh.lunarfront.tech ansible_user=root ansible_ssh_private_key_file=~/.ssh/do" >> inventory.ini
|
|
|
|
- name: Write vault password
|
|
run: echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > .vault_pass
|
|
|
|
- name: Run playbook
|
|
run: |
|
|
ansible-playbook -i inventory.ini ${{ inputs.playbook || 'infra.yml' }} \
|
|
--vault-password-file .vault_pass
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: rm -f ~/.ssh/do .vault_pass
|