Skip to content

Commit d608ca0

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 b22316b commit d608ca0

File tree

4 files changed

+98
-45
lines changed

4 files changed

+98
-45
lines changed

.ansible-lint.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
profile: production
3+
4+
# exclude_paths included in this file are parsed relative to this file's location
5+
# and not relative to the CWD of execution. CLI arguments passed to the --exclude
6+
# option are parsed relative to the CWD of execution.
7+
exclude_paths:
8+
- .cache/ # implicit unless exclude_paths is defined in config
9+
- .github/
10+
11+
use_default_rules: true
12+
enable_list:
13+
- args
14+
- empty-string-compare
15+
- no-log-password
16+
- no-same-owner
17+
warn_list:
18+
- experimental
19+
skip_list:
20+
- name[casing]
21+
- name[prefix]
22+
- yaml[line-length]
23+
- var-naming[no-role-prefix]
24+
25+
# Offline mode disables installation of requirements.yml
26+
offline: false
27+
28+
# Make the output more readable
29+
parseable: true
30+
31+
# Define required Ansible's variables to satisfy syntax check
32+
# extra_vars:
33+
34+
# List of additional kind:pattern to be added at the top of the default
35+
# match list, first match determines the file kind.
36+
kinds:
37+
- tasks: "ansible/tasks/*.yml"
38+
- vars: "ansible/vars.yml"

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ in
1818
verbose = true;
1919
};
2020

21+
ansible-lint = {
22+
enable = true;
23+
verbose = true;
24+
settings = {
25+
configPath = "${../.ansible-lint.yml}";
26+
subdir = "ansible/tests";
27+
};
28+
};
29+
2130
treefmt = {
2231
enable = true;
2332
package = config.treefmt.build.wrapper;

0 commit comments

Comments
 (0)