Ansible #28
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: Ansible | |
on: | |
workflow_dispatch: | |
inputs: | |
IP_publica: | |
type: string | |
description: IP pública de la VM de IBM Cloud | |
required: true | |
jobs: | |
Ansible: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: checks | |
run: whoami && ls -la | |
- name: Setup SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H ${{inputs.IP_publica}} >> ~/.ssh/known_hosts | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.ssh_key }} | |
- name: Install Ansible, curl, docker, kubectl, AZ CLI | |
run: | | |
sudo -i apt update -y && sudo apt upgrade -y | |
sudo -i apt install -y software-properties-common | |
sudo -i add-apt-repository --update ppa:ansible/ansible | |
sudo -i apt -y install ansible | |
sudo apt-get install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg-agent \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | |
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
sudo apt-get install docker-ce docker-ce-cli containerd.io | |
sudo -i apt -y install curl | |
sudo -i curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
sudo -i install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl | |
- name: Generar inventario de ansible | |
run: | | |
cd ansible | |
touch inventory.ini | |
echo "[nodo1]" >> inventory.ini | |
echo "${{inputs.IP_publica}} ansible_user=root ansible_become=true ansible_become_method=sudo" >> inventory.ini | |
- name: Hacer backup de la base de datos en la maquina de backups | |
run: | | |
cd ansible && ansible-playbook -i inventory.ini prueba.yml -u alejandro | |
env: | |
PG_USER: ${{ secrets.PG_USER }} | |
PG_PASSWORD: ${{secrets.PG_PASSWORD}} | |