new version
Some checks failed
Ansible Minecraft CI/CD / Ansible Lint (push) Successful in 8s
Ansible Minecraft CI/CD / Syntax Check (push) Failing after 7s
Ansible Minecraft CI/CD / Deploy to Staging (push) Has been skipped
Ansible Minecraft CI/CD / Deploy to Production (push) Has been skipped

This commit is contained in:
2025-08-27 15:11:08 +02:00
parent 3e64946953
commit 8f0877cd53
105 changed files with 911 additions and 2540 deletions

View File

@@ -1,145 +1,140 @@
name: Ansible Minecraft Server CI/CD
name: Ansible Minecraft CI/CD
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy'
required: true
default: 'staging'
type: choice
options:
- staging
- production
jobs:
lint:
runs-on: ubuntu-latest
name: Ansible Lint
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ansible ansible-lint yamllint
- name: Run yamllint
- name: Lint YAML files
run: |
yamllint -c .yamllint .
yamllint .
continue-on-error: true
- name: Run ansible-lint
- name: Lint Ansible playbooks
run: |
ansible-lint --exclude .gitea/ .
ansible-lint --parseable-severity site.yml roles/
continue-on-error: true
- name: Validate ansible syntax
run: |
ansible-playbook site.yml --syntax-check
test:
syntax-check:
runs-on: ubuntu-latest
name: Syntax Check
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Ansible
run: |
python -m pip install --upgrade pip
pip install ansible
- name: Install Ansible collections
run: |
ansible-galaxy collection install -r requirements.yml
- name: Test playbook structure
run: |
# Verify all roles exist
for role in 01-server_hardening 02-installation-java 03-Installation-Minecraft 04-backups 05-Update; do
if [ ! -d "roles/$role" ]; then
echo "Role $role not found"
exit 1
fi
done
- name: Check inventory files
run: |
ansible-inventory -i inventories/staging/hosts.yml --list
ansible-inventory -i inventories/production/hosts.yml --list
deploy:
runs-on: ubuntu-latest
needs: [lint, test]
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Ansible
run: |
python -m pip install --upgrade pip
pip install ansible
- name: Install collections
run: |
ansible-galaxy collection install -r requirements.yml
- name: Check syntax
run: |
ansible-playbook --syntax-check site.yml -i inventories/staging/hosts.yml
deploy-staging:
runs-on: ubuntu-latest
name: Deploy to Staging
needs: [lint, syntax-check]
if: github.ref == 'refs/heads/develop'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Ansible
run: |
python -m pip install --upgrade pip
pip install ansible
- name: Install collections
run: |
ansible-galaxy collection install -r requirements.yml
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.ANSIBLE_SSH_KEY }}" > ~/.ssh/ansible_key
chmod 600 ~/.ssh/ansible_key
echo "${{ secrets.ANSIBLE_SSH_PRIVATE_KEY }}" | base64 -d > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.STAGING_HOST }} >> ~/.ssh/known_hosts
- name: Setup vault password
- name: Deploy to staging
run: |
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > .vault_pass
chmod 600 .vault_pass
- name: Determine environment
id: env
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "environment=${{ github.event.inputs.environment }}" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "environment=production" >> $GITHUB_OUTPUT
else
echo "environment=staging" >> $GITHUB_OUTPUT
fi
- name: Deploy to environment
ansible-playbook site.yml -i inventories/staging/hosts.yml --check --diff
env:
ANSIBLE_HOST_KEY_CHECKING: false
ANSIBLE_VAULT_PASSWORD_FILE: .vault_pass
run: |
ansible-playbook \
-i inventories/${{ steps.env.outputs.environment }}/hosts.yml \
site.yml \
--limit minecraft_servers \
--diff
MINECRAFT_RCON_PASSWORD: ${{ secrets.MINECRAFT_RCON_PASSWORD }}
ANSIBLE_HOST_KEY_CHECKING: 'false'
- name: Clean up
if: always()
deploy-production:
runs-on: ubuntu-latest
name: Deploy to Production
needs: [lint, syntax-check]
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Ansible
run: |
rm -f ~/.ssh/ansible_key
rm -f .vault_pass
python -m pip install --upgrade pip
pip install ansible
- name: Install collections
run: |
ansible-galaxy collection install -r requirements.yml
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.ANSIBLE_SSH_PRIVATE_KEY }}" | base64 -d > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.PRODUCTION_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to production
run: |
ansible-playbook site.yml -i inventories/production/hosts.yml
env:
MINECRAFT_RCON_PASSWORD: ${{ secrets.MINECRAFT_RCON_PASSWORD }}
ANSIBLE_HOST_KEY_CHECKING: 'false'