Add ansible-lint to CI (#1181)

* Improve Ansible code.

* Add some ansible-lint ignores.

* Add ansible-lint to CI.
This commit is contained in:
Felix Fontein 2025-10-25 11:07:40 +02:00 committed by GitHub
parent b24bce77b6
commit 95bdce75e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 123 additions and 85 deletions

30
.ansible-lint Normal file
View File

@ -0,0 +1,30 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
skip_list:
# Ignore rules that make no sense:
- galaxy[tags]
- galaxy[version-incorrect]
- meta-runtime[unsupported-version]
- no-changed-when
- sanity[cannot-ignore] # some of the rules you cannot ignore actually MUST be ignored, like yamllint:unparsable-with-libyaml
- yaml # we're using yamllint ourselves
- run-once[task] # wtf???
# To be checked and maybe fixed:
- ignore-errors
- key-order[task]
- name[casing]
- name[missing]
- name[play]
- name[template]
- no-free-form
- no-handler
- risky-file-permissions
- risky-shell-pipe
- var-naming[no-reserved]
- var-naming[no-role-prefix]
- var-naming[pattern]
- var-naming[read-only]

View File

@ -216,6 +216,12 @@ remote = [
################################################################################################## ##################################################################################################
[sessions.ansible_lint]
ansible_lint_package = [
"ansible-lint",
"ansible-compat < 25.8.2",
]
[[sessions.ee_check.execution_environments]] [[sessions.ee_check.execution_environments]]
name = "devel-ubi-9" name = "devel-ubi-9"
description = "ansible-core devel @ RHEL UBI 9" description = "ansible-core devel @ RHEL UBI 9"

View File

@ -3,7 +3,7 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
- hosts: "{{ target_hosts }}" - hosts: "{{ target_hosts }}" # noqa: syntax-check[specific]
gather_facts: false gather_facts: false
serial: 1 serial: 1
tasks: tasks:

View File

@ -11,4 +11,4 @@
tasks: tasks:
- name: Setup docker - name: Setup docker
import_role: import_role:
name: setup_docker name: setup_docker # noqa: syntax-check[specific]

View File

@ -11,8 +11,8 @@
tasks: tasks:
- name: Setup docker - name: Setup docker
import_role: import_role:
name: setup_docker name: setup_docker # noqa: syntax-check[specific]
- name: Setup docker Python deps - name: Setup docker Python deps
import_role: import_role:
name: setup_docker_python_deps name: setup_docker_python_deps # noqa: syntax-check[specific]

View File

@ -11,4 +11,4 @@
tasks: tasks:
- name: Setup docker - name: Setup docker
import_role: import_role:
name: setup_docker name: setup_docker # noqa: syntax-check[specific]

View File

@ -20,7 +20,7 @@
advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}" advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
- name: Parameter name should be required - name: Parameter name should be required
community.docker.docker_config: community.docker.docker_config: # noqa: args[module]
state: present state: present
ignore_errors: true ignore_errors: true
register: output register: output
@ -32,7 +32,7 @@
- 'output.msg == "missing required arguments: name"' - 'output.msg == "missing required arguments: name"'
- name: Test parameters - name: Test parameters
community.docker.docker_config: community.docker.docker_config: # noqa: args[module]
name: foo name: foo
state: present state: present
ignore_errors: true ignore_errors: true
@ -261,7 +261,7 @@
community.docker.docker_config: community.docker.docker_config:
name: db_password name: db_password
data: opensesame! data: opensesame!
template_driver: "not a template driver" template_driver: "not a template driver" # noqa: args[module]
state: present state: present
ignore_errors: true ignore_errors: true
register: output register: output

View File

@ -46,7 +46,7 @@
register: result register: result
- name: Extract manifest.json files - name: Extract manifest.json files
ansible.builtin.command: tar xvf "{{ remote_tmp_dir }}/{{ item.file }}" manifest.json --to-stdout ansible.builtin.command: tar xvf "{{ remote_tmp_dir }}/{{ item.file }}" manifest.json --to-stdout # noqa: command-instead-of-module
loop: "{{ image_tasks }}" loop: "{{ image_tasks }}"
loop_control: loop_control:
label: "{{ item.file }}" label: "{{ item.file }}"

View File

@ -15,7 +15,7 @@
advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}" advertise_addr: "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
- name: Parameter name should be required - name: Parameter name should be required
community.docker.docker_secret: community.docker.docker_secret: # noqa: args[module]
state: present state: present
ignore_errors: true ignore_errors: true
register: output register: output
@ -27,7 +27,7 @@
- 'output.msg == "missing required arguments: name"' - 'output.msg == "missing required arguments: name"'
- name: Test parameters - name: Test parameters
community.docker.docker_secret: community.docker.docker_secret: # noqa: args[module]
name: foo name: foo
state: present state: present
ignore_errors: true ignore_errors: true

View File

@ -20,7 +20,7 @@
- name: Create a stack without name - name: Create a stack without name
register: output register: output
community.docker.docker_stack: community.docker.docker_stack: # noqa: args[module]
state: present state: present
ignore_errors: true ignore_errors: true

View File

@ -10,7 +10,7 @@
## Errors ########################################################## ## Errors ##########################################################
#################################################################### ####################################################################
- name: Test parameters with state=join - name: Test parameters with state=join
community.docker.docker_swarm: community.docker.docker_swarm: # noqa: args[module]
state: join state: join
ignore_errors: true ignore_errors: true
register: output register: output
@ -22,7 +22,7 @@
- 'output.msg == "state is join but all of the following are missing: remote_addrs, join_token"' - 'output.msg == "state is join but all of the following are missing: remote_addrs, join_token"'
- name: Test parameters with state=remove - name: Test parameters with state=remove
community.docker.docker_swarm: community.docker.docker_swarm: # noqa: args[module]
state: remove state: remove
ignore_errors: true ignore_errors: true
register: output register: output

View File

@ -11,11 +11,11 @@
tasks: tasks:
- name: Setup docker - name: Setup docker
ansible.builtin.import_role: ansible.builtin.import_role:
name: setup_docker name: setup_docker # noqa: syntax-check[specific]
- name: Setup Docker Python deps - name: Setup Docker Python deps
ansible.builtin.import_role: ansible.builtin.import_role:
name: setup_docker_python_deps name: setup_docker_python_deps # noqa: syntax-check[specific]
- name: Start containers - name: Start containers
community.docker.docker_container: community.docker.docker_container:

View File

@ -8,11 +8,11 @@
tasks: tasks:
- name: Setup docker - name: Setup docker
ansible.builtin.include_role: ansible.builtin.include_role:
name: setup_docker name: setup_docker # noqa: syntax-check[specific]
- name: Setup Docker Python deps - name: Setup Docker Python deps
ansible.builtin.import_role: ansible.builtin.import_role:
name: setup_docker_python_deps name: setup_docker_python_deps # noqa: syntax-check[specific]
# There seems to be no better way to install docker-machine. At least I couldn't find any packages for RHEL7/8. # There seems to be no better way to install docker-machine. At least I couldn't find any packages for RHEL7/8.
- name: Download docker-machine binary - name: Download docker-machine binary

View File

@ -8,7 +8,7 @@
tasks: tasks:
- name: sanity check Docker Machine output - name: sanity check Docker Machine output
vars: vars:
dm_ls_format: !unsafe '{{.Name}} | {{.DriverName}} | {{.State}} | {{.URL}} | {{.Error}}' dm_ls_format: !unsafe '{{.Name}} | {{.DriverName}} | {{.State}} | {{.URL}} | {{.Error}}' # noqa: jinja[invalid]
success_regex: "^vm | [^|]+ | Running | tcp://.+ |$" success_regex: "^vm | [^|]+ | Running | tcp://.+ |$"
ansible.builtin.command: docker-machine ls --format '{{ dm_ls_format }}' ansible.builtin.command: docker-machine ls --format '{{ dm_ls_format }}'
register: result register: result

View File

@ -11,7 +11,7 @@
tasks: tasks:
- name: Setup docker - name: Setup docker
ansible.builtin.import_role: ansible.builtin.import_role:
name: setup_docker name: setup_docker # noqa: syntax-check[specific]
- name: Setup Docker SDK for Python - name: Setup Docker SDK for Python
ansible.builtin.import_role: ansible.builtin.import_role:

View File

@ -4,7 +4,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
- name: Get OS version - name: Get OS version
ansible.builtin.shell: uname -r ansible.builtin.command: uname -r
register: os_version register: os_version
- name: Install pre-reqs - name: Install pre-reqs
@ -35,7 +35,7 @@
name: Add Docker repo on Ubuntu 20 or before, or Debian 11 or before name: Add Docker repo on Ubuntu 20 or before, or Debian 11 or before
block: block:
- name: Add gpg key - name: Add gpg key
ansible.builtin.shell: curl -fsSL https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg >key && apt-key add key ansible.builtin.shell: curl -fsSL https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg >key && apt-key add key # noqa: command-instead-of-module
- name: Add Docker repo - name: Add Docker repo
ansible.builtin.apt_repository: ansible.builtin.apt_repository:

View File

@ -30,7 +30,7 @@
gpgkey: https://download.docker.com/linux/centos/gpg gpgkey: https://download.docker.com/linux/centos/gpg
- name: Update cache - name: Update cache
ansible.builtin.command: yum -y makecache fast ansible.builtin.command: yum -y makecache fast # noqa: command-instead-of-module
- name: Install docker - name: Install docker
ansible.builtin.dnf: ansible.builtin.dnf:

View File

@ -25,7 +25,7 @@
ansible.builtin.set_fact: ansible.builtin.set_fact:
needs_docker_daemon: '{{ not ansible_module_running_in_container }}' needs_docker_daemon: '{{ not ansible_module_running_in_container }}'
- name: - name: Print information
ansible.builtin.debug: ansible.builtin.debug:
msg: |- msg: |-
OS family: {{ ansible_facts.os_family }} OS family: {{ ansible_facts.os_family }}

View File

@ -11,7 +11,7 @@
- name: Setup Docker - name: Setup Docker
when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6'] when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
block: block:
- name: - name: Print information
ansible.builtin.debug: ansible.builtin.debug:
msg: |- msg: |-
OS family: {{ ansible_facts.os_family }} OS family: {{ ansible_facts.os_family }}

View File

@ -11,7 +11,7 @@
- name: Setup Docker - name: Setup Docker
when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6'] when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
block: block:
- name: - name: Print information
ansible.builtin.debug: ansible.builtin.debug:
msg: |- msg: |-
OS family: {{ ansible_facts.os_family }} OS family: {{ ansible_facts.os_family }}

View File

@ -28,5 +28,5 @@
- git+https://github.com/psf/requests - git+https://github.com/psf/requests
- git+https://github.com/urllib3/urllib3 - git+https://github.com/urllib3/urllib3
extra_args: "-c {{ remote_constraints }}" extra_args: "-c {{ remote_constraints }}"
state: latest state: latest # noqa: package-latest
when: force_docker_sdk_for_python_dev | default(false) when: force_docker_sdk_for_python_dev | default(false)

View File

@ -21,12 +21,14 @@
when: ansible_os_family == "Suse" when: ansible_os_family == "Suse"
- ansible.builtin.shell: - ansible.builtin.shell:
# noqa: command-instead-of-module
cmd: | cmd: |
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/*.repo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/*.repo
sed -i 's%#baseurl=http://mirror.centos.org/%baseurl=https://vault.centos.org/%g' /etc/yum.repos.d/*.repo sed -i 's%#baseurl=http://mirror.centos.org/%baseurl=https://vault.centos.org/%g' /etc/yum.repos.d/*.repo
when: ansible_distribution in 'CentOS' and ansible_distribution_major_version == '7' when: ansible_distribution in 'CentOS' and ansible_distribution_major_version == '7'
- ansible.builtin.shell: - ansible.builtin.shell:
# noqa: command-instead-of-module
cmd: | cmd: |
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*.repo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*.repo
sed -i 's%#baseurl=http://mirror.centos.org/$contentdir/$releasever/%baseurl=https://vault.centos.org/8.4.2105/%g' /etc/yum.repos.d/CentOS-Linux-*.repo sed -i 's%#baseurl=http://mirror.centos.org/$contentdir/$releasever/%baseurl=https://vault.centos.org/8.4.2105/%g' /etc/yum.repos.d/CentOS-Linux-*.repo

View File

@ -25,7 +25,7 @@
- when: not podman_setup_marker.stat.exists and not ansible_module_running_in_container - when: not podman_setup_marker.stat.exists and not ansible_module_running_in_container
block: block:
- name: - name: Print information
ansible.builtin.debug: ansible.builtin.debug:
msg: |- msg: |-
OS family: {{ ansible_facts.os_family }} OS family: {{ ansible_facts.os_family }}