ansible-lint during pre-commit in CI/CD

55 Views Asked by At

Locally run ansible-lint pre-commit behaves differently than run during CI/CD.

I use following

---
repos:
  - repo: https://github.com/ansible/ansible-lint
    rev: v24.2.1
    hooks:
      - id: ansible-lint

That is because /etc/ansible/ansible.cfg is available locally which also configures e.g. collection path where private collections are installed.

During the ansible-lint run a requirements.yml is picked up such that dependencies would be installed. Since the collections are private, I would need to hardcode an access token which seems wrong to me. I tried using

---
collections:
  - name: "git+https://<token name>:${token}@<private git repo"
    type: git
    version: "*"

and setting export token=<token with access> but this did not work.

I also tried to use a .ansible-lint config with

---
mock_modules:
  - <namespace>.<name>.<role>

or

mock_roles:
  - <namespace>.<name>.<role>

but not if it helped.

Related questions:

  • How do I make ansible-lint pre-commit behave the same locally and during CI/CD?
  • How to ignore locally available config?
  • How to specify authentication in requirements.yml, e.g. via an environment variable?
0

There are 0 best solutions below