1+ name : Test Ansible Playbook
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ pull_request :
7+ branches : [ main ]
8+ workflow_dispatch :
9+
10+ jobs :
11+ lint :
12+ name : Lint Ansible
13+ runs-on : ubuntu-latest
14+ steps :
15+ - name : Checkout code
16+ uses : actions/checkout@v4
17+
18+ - name : Set up Python
19+ uses : actions/setup-python@v4
20+ with :
21+ python-version : ' 3.11'
22+
23+ - name : Install dependencies
24+ run : |
25+ python -m pip install --upgrade pip
26+ pip install ansible ansible-lint yamllint
27+
28+ - name : Lint YAML files
29+ run : yamllint .
30+
31+ - name : Lint Ansible playbook
32+ run : ansible-lint playbook.yml
33+
34+ test-syntax :
35+ name : Test Ansible Syntax
36+ runs-on : ubuntu-latest
37+ needs : lint
38+ strategy :
39+ matrix :
40+ distribution : ['arch', 'fedora', 'debian']
41+ steps :
42+ - name : Checkout code
43+ uses : actions/checkout@v4
44+
45+ - name : Set up Python
46+ uses : actions/setup-python@v4
47+ with :
48+ python-version : ' 3.11'
49+
50+ - name : Install Ansible
51+ run : |
52+ python -m pip install --upgrade pip
53+ pip install ansible
54+
55+ - name : Test playbook syntax
56+ run : |
57+ ansible-playbook playbook.yml --syntax-check \
58+ -e "current_distro=${{ matrix.distribution }}" \
59+ -e "ansible_user=testuser"
60+
61+ test-playbook :
62+ name : Test Playbook
63+ runs-on : ubuntu-latest
64+ needs : [lint, test-syntax]
65+ strategy :
66+ fail-fast : false
67+ matrix :
68+ include :
69+ - distribution : ubuntu
70+ version : ' 22.04'
71+ container : ' ubuntu:22.04'
72+ - distribution : ubuntu
73+ version : ' 20.04'
74+ container : ' ubuntu:20.04'
75+ - distribution : debian
76+ version : ' 11'
77+ container : ' debian:11'
78+ - distribution : debian
79+ version : ' 12'
80+ container : ' debian:12'
81+ - distribution : fedora
82+ version : ' 39'
83+ container : ' fedora:39'
84+ - distribution : fedora
85+ version : ' 40'
86+ container : ' fedora:40'
87+ - distribution : arch
88+ version : ' latest'
89+ container : ' archlinux:latest'
90+
91+ container :
92+ image : ${{ matrix.container }}
93+ options : --privileged
94+
95+ steps :
96+ - name : Checkout code
97+ uses : actions/checkout@v4
98+
99+ - name : Install dependencies (Ubuntu/Debian)
100+ if : matrix.distribution == 'ubuntu' || matrix.distribution == 'debian'
101+ run : |
102+ apt-get update
103+ apt-get install -y python3 python3-pip sudo curl git systemd
104+ python3 -m pip install ansible
105+
106+ - name : Install dependencies (Fedora)
107+ if : matrix.distribution == 'fedora'
108+ run : |
109+ dnf install -y python3 python3-pip sudo curl git systemd
110+ python3 -m pip install ansible
111+
112+ - name : Install dependencies (Arch)
113+ if : matrix.distribution == 'arch'
114+ run : |
115+ pacman -Sy --noconfirm python python-pip sudo curl git systemd
116+ python -m pip install ansible
117+
118+ - name : Create test user
119+ run : |
120+ useradd -m -s /bin/bash testuser
121+ echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
122+
123+ - name : Run Ansible playbook (dry-run)
124+ if : matrix.distribution != 'arch'
125+ run : |
126+ ansible-playbook playbook.yml \
127+ --connection=local \
128+ --inventory=localhost, \
129+ --limit=localhost \
130+ --check \
131+ --diff \
132+ -e "ansible_user=testuser" \
133+ -e "current_distro=${{ matrix.distribution == 'ubuntu' && 'debian' || matrix.distribution }}"
134+ env :
135+ ANSIBLE_HOST_KEY_CHECKING : false
136+
137+ - name : Run Ansible playbook (syntax-check for Arch)
138+ if : matrix.distribution == 'arch'
139+ run : |
140+ ansible-playbook playbook.yml \
141+ --syntax-check \
142+ -e "ansible_user=testuser" \
143+ -e "current_distro=arch"
144+ env :
145+ ANSIBLE_HOST_KEY_CHECKING : false
146+
147+ test-minimal-install :
148+ name : Test Comprehensive Install
149+ runs-on : ubuntu-latest
150+ needs : [lint, test-syntax]
151+ strategy :
152+ matrix :
153+ tag_set :
154+ - name : " core-cli"
155+ tags : " core,cli"
156+ - name : " development"
157+ tags : " core,dev"
158+ - name : " shell-setup"
159+ tags : " core,shell,common"
160+ container :
161+ image : ubuntu:22.04
162+ options : --privileged
163+
164+ steps :
165+ - name : Checkout code
166+ uses : actions/checkout@v4
167+
168+ - name : Install dependencies
169+ run : |
170+ apt-get update
171+ apt-get install -y python3 python3-pip sudo curl git systemd
172+ python3 -m pip install ansible
173+
174+ - name : Create test user
175+ run : |
176+ useradd -m -s /bin/bash testuser
177+ echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
178+
179+ - name : Run playbook with ${{ matrix.tag_set.name }} tags
180+ run : |
181+ ansible-playbook playbook.yml \
182+ --connection=local \
183+ --inventory=localhost, \
184+ --limit=localhost \
185+ -e "ansible_user=testuser" \
186+ -e "current_distro=debian" \
187+ --tags=${{ matrix.tag_set.tags }}
188+ env :
189+ ANSIBLE_HOST_KEY_CHECKING : false
190+
191+ - name : Verify core packages installation
192+ run : |
193+ echo "Verifying core packages are installed..."
194+ which git || echo "WARNING: git not found"
195+ which curl || echo "WARNING: curl not found"
196+ which sudo || echo "WARNING: sudo not found"
197+ python3 --version || echo "WARNING: python3 not found"
198+
199+ - name : Verify CLI tools installation
200+ if : contains(matrix.tag_set.tags, 'cli')
201+ run : |
202+ echo "Verifying CLI tools are installed..."
203+ which zsh || echo "WARNING: zsh not found"
204+ zsh --version || echo "WARNING: zsh not working"
205+
206+ - name : Verify development tools installation
207+ if : contains(matrix.tag_set.tags, 'dev')
208+ run : |
209+ echo "Verifying development tools..."
210+ which node || echo "WARNING: node not found"
211+ which docker || echo "WARNING: docker not found"
212+
213+ test-roles :
214+ name : Test Individual Roles
215+ runs-on : ubuntu-latest
216+ needs : [lint, test-syntax]
217+ strategy :
218+ fail-fast : false
219+ matrix :
220+ role : [distro-setup, package-manager, common, shell, cli, dev]
221+ distribution : [debian, fedora]
222+ container :
223+ image : ${{ matrix.distribution == 'debian' && 'ubuntu:22.04' || 'fedora:40' }}
224+ options : --privileged
225+
226+ steps :
227+ - name : Checkout code
228+ uses : actions/checkout@v4
229+
230+ - name : Install dependencies (Ubuntu/Debian)
231+ if : matrix.distribution == 'debian'
232+ run : |
233+ apt-get update
234+ apt-get install -y python3 python3-pip sudo curl git systemd
235+ python3 -m pip install ansible
236+
237+ - name : Install dependencies (Fedora)
238+ if : matrix.distribution == 'fedora'
239+ run : |
240+ dnf install -y python3 python3-pip sudo curl git systemd
241+ python3 -m pip install ansible
242+
243+ - name : Create test user
244+ run : |
245+ useradd -m -s /bin/bash testuser
246+ echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
247+
248+ - name : Test role syntax
249+ run : |
250+ ansible-playbook playbook.yml \
251+ --syntax-check \
252+ -e "ansible_user=testuser" \
253+ -e "current_distro=${{ matrix.distribution }}" \
254+ --tags=${{ matrix.role }}
255+ env :
256+ ANSIBLE_HOST_KEY_CHECKING : false
257+
258+ - name : Test role execution (dry-run)
259+ run : |
260+ ansible-playbook playbook.yml \
261+ --connection=local \
262+ --inventory=localhost, \
263+ --limit=localhost \
264+ --check \
265+ --diff \
266+ -e "ansible_user=testuser" \
267+ -e "current_distro=${{ matrix.distribution }}" \
268+ --tags=${{ matrix.role }}
269+ env :
270+ ANSIBLE_HOST_KEY_CHECKING : false
0 commit comments