This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Configure Kubernetes Master Node | |
on: | |
push: | |
branches: | |
- develop | |
- main | |
paths: | |
- .github/workflows/ansible-playbook.yml | |
- 'ansible/**' | |
jobs: | |
configure-master: | |
runs-on: ubuntu-latest | |
steps: | |
# Schritt 1: Repository auschecken | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Schritt 2: Installiere Ansible | |
- name: Install Ansible | |
run: | | |
sudo apt update | |
sudo apt install -y ansible | |
# Schritt 3: Setup SSH Key | |
- name: Setup SSH key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
shell: bash | |
# Schritt 4: Füge die Master-Node zur known_hosts-Datei hinzu | |
# TODO: Aus Inventory Datei auslesen | |
- name: Add server to known hosts | |
run: | | |
echo "Adding server ${{ vars.MASTER_NODE_IP }} to the known hosts" | |
ssh-keyscan -H ${{ vars.MASTER_NODE_IP }} >> ~/.ssh/known_hosts | |
# Schritt 5: Führe das Ansible-Playbook aus | |
- name: Run Ansible Playbook | |
working-directory: ansible | |
run: | | |
inv_file="inventory/staging" | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
inv_file="inventory/production" | |
fi | |
ansible-playbook -i "$inv_file" master-setup.yml |