Skip to content

Commit 22b404b

Browse files
committedDec 5, 2024
init switch to raw ansible
1 parent 747f7d2 commit 22b404b

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
 

‎.forgejo/workflows/ansibleCD.yml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Ansible Deploy to Hosts
2+
on:
3+
pull_request:
4+
types: [closed]
5+
6+
jobs:
7+
deploy:
8+
if: github.event.pull_request.merged == true
9+
runs-on: docker
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Fetch all history for git diff
15+
run: git fetch --depth=2
16+
17+
- name: Detect modified folders
18+
id: detect-changes
19+
run: |
20+
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
21+
git fetch --unshallow
22+
fi
23+
folders=$(git diff --name-only HEAD~1 HEAD | grep '^docker/' | cut -d/ -f2 | sort | uniq)
24+
echo "Modified folders: $folders"
25+
echo "::set-output name=folders::$folders"
26+
27+
- name: Deploy to hosts
28+
run: |
29+
IFS=' ' read -r -a folder_array <<< "${{ steps.detect-changes.outputs.folders }}"
30+
for folder in "${folder_array[@]}"; do
31+
case $folder in
32+
actual)
33+
target_host="ubu.lan"
34+
;;
35+
arrs)
36+
target_host="arrs.lan"
37+
;;
38+
arm)
39+
target_host="arm.lan"
40+
;;
41+
AI)
42+
target_host="ai.lan"
43+
;;
44+
authentik)
45+
target_host="auth.lan"
46+
;;
47+
ag-main)
48+
target_host="dns.lan"
49+
;;
50+
exporters)
51+
target_host="all"
52+
;;
53+
grafana)
54+
target_host="ubu.lan"
55+
;;
56+
jellyfin)
57+
target_host="jf.lan"
58+
;;
59+
kasm)
60+
target_host="kasm.lan"
61+
;;
62+
netboot)
63+
target_host="netboot.lan"
64+
;;
65+
nexterm)
66+
target_host="ubu.lan"
67+
;;
68+
npm)
69+
target_host="npm.lan"
70+
;;
71+
paperless)
72+
target_host="ubu.lan"
73+
;;
74+
portainer)
75+
target_host="port.lan"
76+
;;
77+
runner)
78+
target_host="runner.lan"
79+
;;
80+
# Add cases for other folders/hosts
81+
*)
82+
echo "Unknown folder: $folder"
83+
exit 1
84+
;;
85+
esac
86+
echo "Deploying to $target_host for folder $folder"
87+
88+
- name: Run Ansible Playbook
89+
uses: docker://mafyuh/ansible-bws:v1.0.0
90+
with:
91+
args: ansible-playbook -i hosts.ini /playbooks/deploy-docker.yml --extra-vars "target_host=$target_host folder=$folder"
92+
env:
93+
BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }}

‎ansible/ansible.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[defaults]
2+
inventory = ./hosts.ini
3+
ansible_user = mafyuh
4+
host_key_checking = False

‎ansible/hosts.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[iac]
2+
arrs.lan ansible_host={{ lookup('bitwarden.secrets.lookup', 267abc49-f755-4c88-a2a8-b23d00503e31) }}

0 commit comments

Comments
 (0)
Please sign in to comment.