-
Notifications
You must be signed in to change notification settings - Fork 0
36 lines (30 loc) · 1.19 KB
/
ansible.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
name: Run Ansible Playbook
on:
push:
branches:
- main # or your desired branch
jobs:
run-playbook:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Ansible and sshpass
run: |
sudo apt update
sudo apt install -y ansible openssh-client sshpass # Install sshpass for password-based SSH authentication
- name: Create dynamic inventory.ini
run: |
mkdir -p ansible # Ensure the ansible directory exists
echo "[vps]" > ansible/inventory.ini
echo "${{ secrets.VPS_IP }}" >> ansible/inventory.ini
echo "[vps:vars]" >> ansible/inventory.ini
echo "ansible_ssh_user=${{ secrets.ANSIBLE_SSH_USER }}" >> ansible/inventory.ini
echo "ansible_ssh_pass=${{ secrets.VPS_SSH_PASSWORD }}" >> ansible/inventory.ini
- name: Add VPS SSH key to known hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.VPS_IP }} >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Run Ansible playbook with password
run: ansible-playbook ansible/playbook.yml -i ansible/inventory.ini