[Ansible-lint] Upgrade sonarscanner docker image to Alpine v3.15

Hello,

I wanted to install ansible-lint to perform a better analysis of my ansible code. The PIP install doesn’t work.

But since the 3.15 version of Alpine, there are a community package for ansible-lint

https://pkgs.alpinelinux.org/packages?name=ansible-lint&branch=v3.15

So i added the community repo with a 3.15 version…

With this trick i can install ansible and ansible-lint easily

- echo "https://dl-cdn.alpinelinux.org/alpine/v3.15/community/" >> /etc/apk/repositories
- 'cat /etc/apk/repositories'
- 'apk update'
- 'apk add ansible ansible-lint'

Thanks for your help !

David

OK i have some issues with the ansible-lint version check :

Upgrade sonar-scanner image from 3.14 to 3.15 :

sed -i "s/3.14/3.15/g" /etc/apk/repositories

apk update && apk upgrade --available && sync && apk --no-cache add ca-certificates ansible ansible-lint

Seems to work :

(40/40) Installing ansible-lint (4.3.7-r4)
Executing busybox-1.34.1-r5.trigger
OK: 574 MiB in 59 packages

Version check :

/ # ansible --version
ansible [core 2.11.6] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.7 (default, Nov 24 2021, 21:15:59) [GCC 10.3.1 20211027]
  jinja version = 3.0.1
  libyaml = True

Ansible-lint returns an unknown version…

/ # ansible-lint  --version
ansible-lint unknown

ansible-lint seems to work just fine

/asqatasun # /usr/bin/ansible-lint -v
INFO     Discovering files to lint: git ls-files *.yaml *.yml
INFO     Unknown file type: deploiement.yml
INFO     Unknown file type: installation.yml
INFO     Unknown file type: integration.yml
INFO     Found roles: roles/deploiement roles/installation
INFO     Found playbooks:
WARNING  Listing 55 violation(s) that are fatal
[208] File permissions unset or incorrect
...

The SonarQube ansible plugin checks the version and fail :

INFO: ansible-lint version:
WARN: Messages printed to error output during analysis:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/pkg_resources/__init__.py", line 568, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3.9/site-packages/pkg_resources/__init__.py", line 886, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.9/site-packages/pkg_resources/__init__.py", line 777, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (resolvelib 0.5.2 (/usr/lib/python3.9/site-packages), Requirement.parse('resolvelib<0.6.0,>=0.5.3'), {'ansible-core'})
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/bin/ansible-lint", line 33, in <module>
    sys.exit(load_entry_point('ansible-lint==4.3.7', 'console_scripts', 'ansible-lint')())
  File "/usr/bin/ansible-lint", line 25, in importlib_load_entry_point
    return next(matches).load()
"""Ansible-lint version information."""

try:
    import pkg_resources
except ImportError:
    pass


try:
    __version__ = pkg_resources.get_distribution('ansible-lint').version
except Exception:
    __version__ = 'unknown'

I thinks it’s some issues in the Alpine packaging

https://pkgs.alpinelinux.org/package/v3.15/community/x86_64/ansible-lint

I’ll try to contact the maintainer…

Next try : edge repository

I’ve two packages problem with the ansible-lint plugin

I also need the resolvelib package to be >=0.5.3 and to add yamllint

pkg_resources.ContextualVersionConflict: (resolvelib 0.5.2 (/usr/lib/python3.9/site-packages), Requirement.parse('resolvelib<0.6.0,>=0.5.3'), {'ansible-core'})
During handling of the above exception, another exception occurred:

In the edge repository, it’s fine :

https://pkgs.alpinelinux.org/package/edge/community/x86_64/ansible-lint
https://pkgs.alpinelinux.org/package/edge/community/x86_64/py3-resolvelib

so i’ve updated my sonar-scanner image…

sed -i "s/v3.14/edge/g" /etc/apk/repositories

apk update && apk upgrade --available && sync && apk --no-cache add ca-certificates ansible ansible-lint yamllint

# ansible-lint --version
ansible-lint 6.0.2 using ansible 2.12.4

and it works :

INFO: Sensor Ansible Lint Sensor [ansible] (done) | time=60131ms

Hope it helps someone !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.