Skip to content

Commit 6371f59

Browse files
kaapstormclaude
andcommitted
Fix all ansible-lint production profile violations
Resolves all 151 violations flagged by ansible-lint at the production profile. Changes by category: yaml[truthy] Replace yes/no with true/false throughout all task files, defaults, handlers, molecule playbooks and inventory group_vars. name[play], name[missing], name[template] Name every previously-unnamed play and include_tasks call; rewrite task names that embed Jinja templates in a non-trailing position to use plain English descriptions instead. no-changed-when Add changed_when to every command/shell/raw task that lacked it: - 'Test' echo task (changed_when: false) - mkswap / swapon swap tasks (changed_when reflects actual change) - raw bootstrap tasks in molecule prepare playbooks (changed_when: false) - Superset admin-user create command (changed_when: true — always runs) - nginx test-and-reload shell (changed_when: true) risky-file-permissions Add mode: "0644" to nginx config template tasks that were missing it. command-instead-of-module Replace 'command: systemctl daemon-reload' handler with ansible.builtin.systemd(daemon_reload: true). Suppress the remaining curl|sh uv-installer task with # noqa since the uv standalone installer has no module equivalent. risky-shell-pipe Add set -o pipefail to the uv installer shell command. jinja[spacing] Fix {{home_dir}}/www → {{ home_dir }}/www in django defaults. yaml[brackets], yaml[trailing-spaces], yaml[indentation] Fix formatting in .github/workflows/molecule-test.yml. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2a0782c commit 6371f59

32 files changed

Lines changed: 240 additions & 162 deletions

File tree

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1+
---
12
name: Molecule Test
23

34
on:
45
push:
5-
branches: [ master, nh/refactor ]
6+
branches: [master, nh/refactor]
67
pull_request:
7-
branches: [ master, nh/refactor ]
8-
8+
branches: [master, nh/refactor]
99
jobs:
1010
test:
1111
name: Molecule Test
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
1515
role: [postgres, redis, nginx]
16-
1716
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v4
20-
21-
- name: Set up Python
22-
uses: actions/setup-python@v4
23-
with:
24-
python-version: '3.11'
25-
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
pip install ansible molecule molecule-docker docker
30-
ansible-galaxy collection install -r requirements.yml
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: "3.11"
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install ansible molecule molecule-docker docker
29+
ansible-galaxy collection install -r requirements.yml
3130
32-
- name: Run Molecule test
33-
run: |
34-
cd roles/${{ matrix.role }}
35-
molecule test
36-
env:
37-
PY_COLORS: '1'
38-
ANSIBLE_FORCE_COLOR: '1'
31+
- name: Run Molecule test
32+
run: |
33+
cd roles/${{ matrix.role }}
34+
molecule test
35+
env:
36+
PY_COLORS: "1"
37+
ANSIBLE_FORCE_COLOR: "1"

.readthedocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
23

34
version: 2

commcare_sync.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
# Issue: https://github.com/ansible/ansible/issues/57529#issuecomment-513143430
3-
- hosts: all
3+
- name: Gather facts
4+
hosts: all
45

56
- name: Create CommCare Data Pipeline server.
67
hosts: all
7-
become: yes
8+
become: true
89
become_user: root
910

10-
gather_facts: no
11-
11+
gather_facts: false
1212

1313
roles:
1414
- postgres
@@ -18,5 +18,3 @@
1818
when: superset_enabled
1919
- django
2020
- commcare_sync
21-
22-
...

git-hooks/install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
function usage()
4+
{
5+
cat << EOF
6+
usage: $0 options
7+
8+
This script installs git hooks
9+
10+
OPTIONS:
11+
-h Show this message
12+
-f don't ask before overwriting your current git hooks
13+
-r remove existing hooks but do not add the new ones
14+
EOF
15+
}
16+
17+
OPT='-i'
18+
FUNC='link_hooks'
19+
20+
while getopts "hfr" OPTION
21+
do
22+
case $OPTION in
23+
h)
24+
usage
25+
exit
26+
;;
27+
f)
28+
OPT='-f'
29+
;;
30+
r)
31+
FUNC='remove_hooks'
32+
;;
33+
?)
34+
usage
35+
exit 1
36+
;;
37+
esac
38+
done
39+
40+
function link_hooks() {
41+
hook=$1
42+
base_path=$2
43+
ln -s -f $OPT ../../git-hooks/$hook.sh $base_path/hooks/$hook
44+
}
45+
46+
function remove_hooks() {
47+
hook=$1
48+
base_path=$2
49+
rm $OPT $base_path/hooks/$hook
50+
}
51+
52+
${FUNC} 'pre-commit' '.git'

git-hooks/pre-commit.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
#
3+
# Pre-commit hook that verifies if all files containing 'vault' in the name
4+
# are encrypted.
5+
# If not, commit will fail with an error message
6+
#
7+
# File should be .git/hooks/pre-commit and executable
8+
VAULT_FILE_INCLUDE_PATTERN='(/vault.yml|.*.vault|.*vault.*)$'
9+
VAULT_FILE_EXCLUDE_PATTERN='^tests|development|^src/commcare_cloud/environment/secrets/backends/ansible_vault/|src/commcare_cloud/manage_commcare_cloud/list_vault_keys.py'
10+
REQUIRED='ANSIBLE_VAULT'
11+
12+
EXIT_STATUS=0
13+
wipe="\033[1m\033[0m"
14+
yellow='\033[1;33m'
15+
# carriage return hack. Leave it on 2 lines.
16+
cr='
17+
'
18+
for f in $(git diff --cached --name-only | grep -E "$VAULT_FILE_INCLUDE_PATTERN" | grep -E -v "$VAULT_FILE_EXCLUDE_PATTERN")
19+
do
20+
MATCH=`grep -L $REQUIRED $f | head -n 1`
21+
if [ -n "${MATCH// }" ] ; then
22+
UNENCRYPTED_FILES="$f$cr$UNENCRYPTED_FILES"
23+
EXIT_STATUS=1
24+
fi
25+
done
26+
if [ $EXIT_STATUS = 0 ] ; then
27+
exit 0
28+
else
29+
echo '# COMMIT REJECTED'
30+
echo '# Looks like unencrypted ansible-vault files are part of the commit:'
31+
echo '#'
32+
while read -r line; do
33+
if [ -n "$line" ]; then
34+
echo -e "#\t${yellow}unencrypted: $line${wipe}"
35+
fi
36+
done <<< "$UNENCRYPTED_FILES"
37+
echo '#'
38+
echo "# Please encrypt them with 'ansible-vault encrypt <file>'"
39+
echo "# (or force the commit with '--no-verify')."
40+
exit $EXIT_STATUS
41+
fi

inventories/dev/group_vars/commcare_sync/vars.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
public_host: 192.168.11.10
44

5-
superset_enabled: yes
6-
superset_public_host: superset.vagrant.local # this needs to be manually mapped to 192.168.11.10 in /etc/hosts
5+
superset_enabled: true
6+
superset_public_host: superset.vagrant.local # this needs to be manually mapped to 192.168.11.10 in /etc/hosts
77
superset_feature_flags: []
8-
98
app_user: "{{ ansible_user }}"
109

11-
django_allow_public_signups: no
10+
django_allow_public_signups: false
1211

1312
# These variables are encrypted and stored in an ansible vault:
1413
vault_default_db_password: <secret1>
1514
vault_default_superset_password: <secret2>
1615
vault_mapbox_api_key: <secret3>
1716
vault_django_secret_key: <secret4>
18-
vault_django_fernet_keys: '["<secret5>"]' # JSON-formatted list
17+
vault_django_fernet_keys: '["<secret5>"]' # JSON-formatted list
1918
vault_superset_secret_key: <secret6>
20-
...

inventories/dev/hosts.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ all:
1111
commcare_sync:
1212
hosts:
1313
local1:
14-
15-
...

inventories/example/group_vars/commcare_sync/vars.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public_host: commcare-sync.example.com
44

5-
superset_enabled: yes
5+
superset_enabled: true
66
superset_public_host: superset.example.com
77

88
app_user: "{{ ansible_user }}"
@@ -11,6 +11,4 @@ app_user: "{{ ansible_user }}"
1111
postgresql_backup_enabled: false
1212
# Add any other DBs separated with spaces
1313
postgresql_backup_db_list: "superset"
14-
postgresql_backups_to_keep: 5 # 0 will ignore this setting
15-
16-
...
14+
postgresql_backups_to_keep: 5 # 0 will ignore this setting

inventories/example/hosts.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ all:
1111
commcare_sync:
1212
hosts:
1313
local1:
14-
...

roles/commcare_sync/defaults/main.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@
33
ansible_python_interpreter: /usr/bin/python3
44
base_python_package: "python3"
55

6-
apt_update_cache: yes
6+
apt_update_cache: true
77

8-
swap_file_enabled: no
8+
swap_file_enabled: false
99
swap_file: /swapfile
1010
swap_file_size_kb: 512
1111

12-
ssl_enabled: no
12+
ssl_enabled: false
1313

1414
superset_secret_key: "{{ vault_superset_secret_key }}"
1515

16-
certbot_auto_renew: yes
16+
certbot_auto_renew: true
1717

1818
certbot_script: /opt/certbot-auto
1919
certbot_dir: /etc/letsencrypt
2020
certbot_admin_email: admin@example.com
2121
certbot_domains:
2222
- example.com
2323
- www.example.com
24-
25-
...

0 commit comments

Comments
 (0)