Skip to content

Commit 49c5321

Browse files
authored
Use same dependencies for ansible-lint as actual environment (#967)
* use same deps for ansible lint as actual environment * avoid ansible-lint install upgrading ansible-core * workaround galaxy installs * ignore galaxy-installed collections when ansible-linting * fix local superlinter * remove deprecated VALIDATE_TERRAFORM_TERRASCAN setting * move superlinter before galaxy installs so it doens't lint them * ensure ansible-lint always runs even if superlinter fails * add pip caching to linting * turn off checkov again locally, cpu usage too high * fixup requirements
1 parent 90864ec commit 49c5321

5 files changed

Lines changed: 46 additions & 14 deletions

File tree

.ansible-lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ skip_list:
1313
exclude_paths:
1414
- actionlint.yml
1515
- .ansible/
16+
- ansible/collections/
1617
- .github/
1718
# Rule 'syntax-check' is unskippable, you cannot use it in 'skip_list' or 'warn_list'.
1819
# It breaks the parser which takes place before the linter, the only option is to exclude the file.

.github/workflows/lint.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ jobs:
2626
submodules: true
2727
persist-credentials: false
2828

29-
- name: Run ansible-lint
30-
uses: ansible/ansible-lint@a2bc8b8b13a80802215856c56823d85007d3baf5 # v25.12.2
31-
env:
32-
ANSIBLE_COLLECTIONS_PATH: .ansible/collections
29+
- name: Cache pip
30+
# Don't cache galaxy/requirements.yml as during dev its common for this
31+
# to use branch names
32+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
33+
with:
34+
path: ~/.cache/pip
35+
key: pip-${{ hashFiles('requirements.txt') }}
3336

3437
- name: Load super-linter configuration
3538
# Use grep inverse matching to exclude eventual comments in the .env file
@@ -38,10 +41,23 @@ jobs:
3841
# yamllint disable-line rule:line-length
3942
# Ref: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
4043
run: grep -v '^#' super-linter.env >> "$GITHUB_ENV"
41-
if: always()
4244

4345
- name: Run super-linter
4446
uses: super-linter/super-linter/slim@61abc07d755095a68f4987d1c2c3d1d64408f1f9 # v8.5.0
45-
if: always()
4647
env:
4748
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Install ansible etc
51+
# NB: could prepend to path using GITHUB_PATH but don't want to check
52+
# if that messes with superlinter
53+
run: dev/setup-env.sh
54+
if: always()
55+
56+
- name: Run ansible-lint
57+
# use offline mode galaxy roles/collections already installed
58+
# but build a list so we can ignore them
59+
run: |
60+
. venv/bin/activate
61+
mapfile -t excludes < <(git ls-files --others --ignored --exclude-standard --directory ansible/roles/)
62+
ansible-lint --offline --config-file .ansible-lint.yml --exclude "${excludes[@]}"
63+
if: always()

dev/run-linters

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Disabled linters: checkov stays stuck for some reason!
88
# VALIDATE_GITLEAKS=false is controversial because that's the best time to catch errors
99

10-
if [ "$1" = "-f" ] || [ "$1" = "--false" ]; then
10+
if [ "$1" = "-f" ] || [ "$1" = "--fast" ]; then
1111
echo "Disabling slow linters: ansible-lint and gitleaks"
1212
VALIDATE_ANSIBLE_LINT=false
1313
export VALIDATE_GITLEAKS=false
@@ -16,9 +16,10 @@ fi
1616
if [ "${VALIDATE_ANSIBLE_LINT:-true}" = true ]; then
1717
echo "Running ansible-lint $*..."
1818
ansible_lint_failed=false
19-
# Specifying `ANSIBLE_COLLECTIONS_PATH` ensures `ansible-lint` downloads collections and roles under the `.ansible` directory, separating them from our own roles under the `ansible` directory.
20-
# We exclude these downloaded files from linting by listing `.ansible` under `exclude_paths` in `.ansible-lint.yml`.
21-
if ! ANSIBLE_COLLECTIONS_PATH=.ansible/collections ansible-lint -c .ansible-lint.yml "$@"; then
19+
# Create an array of uncommitted role paths:
20+
mapfile -t excludes < <(git ls-files --others --ignored --exclude-standard --directory ansible/roles/)
21+
# Run ansible-lint in offline mode so it doesn't download galaxy requirements itself, ignoring galaxy-installed roles:
22+
if ! ansible-lint --offline --config-file .ansible-lint.yml --exclude "${excludes[@]}" "$@"; then
2223
echo "ansible-lint found errors"
2324
ansible_lint_failed=true
2425
fi

requirements.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
ansible-core==2.16.0
1+
ansible-compat==26.3.0
2+
ansible-core==2.16.14
3+
ansible-lint==25.12.2
24
arrow==1.4.0
35
attrs==25.4.0
46
autopage==0.5.2
57
bcrypt==4.3.0
68
beautifulsoup4==4.13.3
79
binaryornot==0.4.4
10+
black==26.5.1
11+
bracex==2.6
812
certifi==2025.11.12
913
cffi==2.0.0
1014
chardet==5.2.0
@@ -18,7 +22,9 @@ cryptography==46.0.5
1822
cycler==0.12.1
1923
debtcollector==3.0.0
2024
decorator==5.2.1
25+
distro==1.9.0
2126
dogpile.cache==1.5.0
27+
filelock==3.29.0
2228
fonttools==4.60.1
2329
idna==3.11
2430
iso8601==2.1.0
@@ -35,6 +41,7 @@ MarkupSafe==3.0.3
3541
matplotlib==3.10.7
3642
mdurl==0.1.2
3743
msgpack==1.1.2
44+
mypy_extensions==1.1.0
3845
netaddr==1.3.0
3946
numpy==2.3.5
4047
openstacksdk==4.8.0
@@ -48,6 +55,7 @@ oslo.serialization==5.8.0
4855
oslo.utils==9.2.0
4956
packaging==23.2
5057
passlib==1.7.4
58+
pathspec==1.1.1
5159
pbr==7.0.3
5260
pillow==12.1.1
5361
platformdirs==4.5.0
@@ -64,6 +72,7 @@ python-keystoneclient==5.7.0
6472
python-manilaclient==5.7.0
6573
python-openstackclient==8.0.0
6674
python-slugify==8.0.4
75+
pytokens==0.4.1
6776
PyYAML==6.0.3
6877
referencing==0.37.0
6978
requests==2.31.0
@@ -73,15 +82,20 @@ rfc3986==2.0.0
7382
rich==14.2.0
7483
rich-argparse==1.7.2
7584
rpds-py==0.29.0
85+
ruamel.yaml==0.19.1
86+
ruamel.yaml.clib==0.2.15
7687
schema==0.7.8
7788
setuptools==80.9.0
7889
six==1.17.0
7990
soupsieve==2.8
8091
stevedore==5.6.0
92+
subprocess-tee==0.4.2
8193
text-unidecode==1.3
8294
toml==0.10.2
8395
typing_extensions==4.15.0
8496
tzdata==2025.2
8597
urllib3==2.5.0
98+
wcmatch==10.1
8699
wcwidth==0.2.14
87100
wrapt==2.0.1
101+
yamllint==1.38.0

super-linter.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Detect that default branch is devel when running locally
22
DEFAULT_BRANCH=main
33

4+
# Ignore files git ignores
5+
IGNORE_GITIGNORED_FILES=true
6+
47
# Don't add a big table with lint results as a PR comment
58
ENABLE_GITHUB_PULL_REQUEST_SUMMARY_COMMENT=false
69

@@ -23,9 +26,6 @@ VALIDATE_PYTHON_RUFF_FORMAT=false
2326
# Don't validate YAML prettier because yamllint is sufficient
2427
VALIDATE_YAML_PRETTIER=false
2528

26-
# Getting false positives with terrascan that seemingly can't be masked
27-
VALIDATE_TERRAFORM_TERRASCAN=false
28-
2929
# Doesn't seem possible to exclude files with terragrunt
3030
VALIDATE_TERRAGRUNT=false
3131

0 commit comments

Comments
 (0)