Skip to content

Commit 7388b0b

Browse files
committed
feat: add ansible-lint validation for test playbooks
Configure pre-commit hook to run ansible-lint on test playbooks and their dependencies. Since test playbooks include tasks from existing task files, ansible-lint automatically validates those dependencies as well.
1 parent a99ea10 commit 7388b0b

File tree

4 files changed

+61
-45
lines changed

4 files changed

+61
-45
lines changed

.ansible-lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+

ansible/tasks/setup-nginx.yml

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,82 @@
1-
- name: nginx - system user
1+
---
2+
- name: Nginx - system user
23
ansible.builtin.user:
3-
name: 'nginx'
4-
state: 'present'
4+
name: nginx
5+
state: present
56

67
# Kong installation steps from http://archive.vn/3HRQx
7-
- name: nginx - system dependencies
8+
- name: Nginx - system dependencies
89
ansible.builtin.apt:
910
pkg:
1011
- libpcre3-dev
1112
- libssl-dev
1213
- openssl
1314
- zlib1g-dev
1415

15-
- name: nginx - download source
16+
- name: Nginx - download source
1617
ansible.builtin.get_url:
1718
checksum: "{{ nginx_release_checksum }}"
18-
dest: '/tmp/nginx-{{ nginx_release }}.tar.gz'
19-
url: "https://nginx.org/download/nginx-{{ nginx_release }}.tar.gz"
19+
dest: /tmp/nginx-{{ nginx_release }}.tar.gz
20+
url: https://nginx.org/download/nginx-{{ nginx_release }}.tar.gz
21+
mode: '0640'
2022

21-
- name: nginx - unpack archive
23+
- name: Nginx - unpack archive
2224
ansible.builtin.unarchive:
23-
dest: '/tmp'
25+
dest: /tmp
2426
remote_src: true
25-
src: "/tmp/nginx-{{ nginx_release }}.tar.gz"
27+
src: /tmp/nginx-{{ nginx_release }}.tar.gz
2628

27-
- name: nginx - configure
29+
- name: Nginx - configure
2830
ansible.builtin.command:
2931
argv:
30-
- ./configure
31-
- --prefix=/usr/local/nginx
32-
- --conf-path=/etc/nginx/nginx.conf
33-
- --with-http_ssl_module
34-
- --with-http_realip_module
32+
- ./configure
33+
- --prefix=/usr/local/nginx
34+
- --conf-path=/etc/nginx/nginx.conf
35+
- --with-http_ssl_module
36+
- --with-http_realip_module
3537
- --with-threads
38+
creates: /tmp/nginx-{{ nginx_release }}/Makefile
3639
args:
37-
chdir: "/tmp/nginx-{{ nginx_release }}"
40+
chdir: /tmp/nginx-{{ nginx_release }}
3841
become: true
3942

40-
- name: nginx - build and install
43+
- name: Nginx - build and install
4144
community.general.make:
42-
chdir: "/tmp/nginx-{{ nginx_release }}"
45+
chdir: /tmp/nginx-{{ nginx_release }}
4346
jobs: "{{ parallel_jobs | default(omit) }}"
4447
target: "{{ make_target }}"
4548
become: true
4649
loop:
47-
- 'build'
48-
- 'install'
50+
- build
51+
- install
4952
loop_control:
50-
loop_var: 'make_target'
53+
loop_var: make_target
5154

52-
- name: nginx - hand over ownership of /etc/nginx and /usr/local/nginx to user nginx
55+
- name: Nginx - hand over ownership of /etc/nginx and /usr/local/nginx to user nginx
5356
ansible.builtin.file:
54-
owner: 'nginx'
57+
owner: nginx
5558
path: "{{ nginx_dir_item }}"
5659
recurse: true
5760
loop:
5861
- /etc/nginx
5962
- /usr/local/nginx
6063
loop_control:
61-
loop_var: 'nginx_dir_item'
64+
loop_var: nginx_dir_item
6265

6366
# [warn] ulimit is currently set to "1024". For better performance set it to at least
6467
# "4096" using "ulimit -n"
65-
- name: nginx - bump up ulimit
68+
- name: Nginx - bump up ulimit
6669
community.general.pam_limits:
67-
domain: 'nginx'
68-
limit_item: 'nofile'
69-
limit_type: 'soft'
70-
value: '4096'
70+
domain: nginx
71+
limit_item: nofile
72+
limit_type: soft
73+
value: "4096"
7174

72-
- name: nginx - create service file
75+
- name: Nginx - create service file
7376
ansible.builtin.template:
74-
dest: '/etc/systemd/system/nginx.service'
75-
src: 'files/nginx.service.j2'
77+
dest: /etc/systemd/system/nginx.service
78+
src: files/nginx.service.j2
79+
mode: '0644'
7680

7781
# Keep it dormant for the timebeing
7882

ansible/tests/nginx.yaml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
2-
- hosts: localhost
2+
- name: Setup Nginx Server
3+
hosts: localhost
34
tasks:
4-
- name: Install dependencies
5-
apt:
6-
pkg:
7-
- build-essential
8-
update_cache: yes
9-
- import_tasks: ../tasks/setup-nginx.yml
10-
- name: Start Nginx service
11-
service:
12-
name: nginx
13-
state: started
14-
enabled: yes
5+
- name: Install dependencies
6+
ansible.builtin.apt:
7+
pkg:
8+
- build-essential
9+
update_cache: true
10+
- name: Setup Nginx using existing task file
11+
ansible.builtin.import_tasks: ../tasks/setup-nginx.yml
12+
- name: Start Nginx service
13+
ansible.builtin.service:
14+
name: nginx
15+
state: started
16+
enabled: true

nix/hooks.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ in
2121
verbose = true;
2222
};
2323

24+
ansible-lint = {
25+
enable = true;
26+
verbose = true;
27+
settings = {
28+
subdir = "ansible/tests";
29+
};
30+
};
31+
2432
treefmt = {
2533
enable = true;
2634
package = config.treefmt.build.wrapper;

0 commit comments

Comments
 (0)