Browse Source

Update ansible-lint and add fake zuul_return

- Use zuul_return fake module to make ansible lint happy, this allows
  to remove Zuul import.
- While ansible-lint 4.2.0 is now able to detect playbooks/roles, this
  is broken, so don't use it
- move its config out of tox.ini so it can be used by any tools, or
  without tox

Change-Id: Ie8935f47db855647e19ae091044e5ac1871f1551
Co-Authored-By: Sorin Sbarnea <ssbarnea@redhat.com>
Co-Authored-By: Andreas Jaeger <aj@suse.com>
changes/75/702575/7
Ian Wienand 1 year ago
committed by Andreas Jaeger
parent
commit
0326363e48
9 changed files with 42 additions and 23 deletions
  1. +12
    -0
      .ansible-lint
  2. +1
    -1
      playbooks/proposal/propose-updates.yaml
  3. +1
    -1
      playbooks/publish/openstack-artifacts.yaml
  4. +1
    -1
      playbooks/translation/openstack-translation-artifacts.yaml
  5. +1
    -1
      playbooks/translation/upstream-translation-update.yaml
  6. +3
    -3
      roles/test-upload-logs/tasks/main.yaml
  7. +5
    -5
      roles/use-cached-repos/tasks/main.yaml
  8. +12
    -0
      tests/fake-ansible/library/zuul_return.py
  9. +6
    -11
      tox.ini

+ 12
- 0
.ansible-lint View File

@ -0,0 +1,12 @@
exclude_paths:
- zuul.d/
- grafana/
- nodepool/
- ../../opendev
parseable: true
quiet: false
skip_list:
- '204' # [E204] Lines should be no longer than 120 chars
- '301' # [E301] Commands should not change things if nothing needs doing
- '306' # [E306] Shells that use pipes should set the pipefail option
verbosity: 1

+ 1
- 1
playbooks/proposal/propose-updates.yaml View File

@ -2,7 +2,7 @@
tasks:
- name: Run propose_update.sh script
command: "{{ ansible_user_dir }}/scripts/propose_update.sh {{ update_target }} {{zuul.branch}}"
command: "{{ ansible_user_dir }}/scripts/propose_update.sh {{ update_target }} {{ zuul.branch }}"
args:
chdir: "src/{{ zuul.project.canonical_name }}"
environment: '{{ zuul | zuul_legacy_vars }}'

+ 1
- 1
playbooks/publish/openstack-artifacts.yaml View File

@ -9,7 +9,7 @@
name: upload-afs-synchronize
vars:
afs_source: "{{ zuul.executor.work_root }}/artifacts/"
afs_target: "/afs/.openstack.org/project/tarballs.opendev.org/{{ zuul.project.name}}/"
afs_target: "/afs/.openstack.org/project/tarballs.opendev.org/{{ zuul.project.name }}/"
- name: Destroy AFS token
include_role:
name: destroy-afs-token


+ 1
- 1
playbooks/translation/openstack-translation-artifacts.yaml View File

@ -9,7 +9,7 @@
name: upload-afs-synchronize
vars:
afs_source: "{{ zuul.executor.work_root }}/artifacts/"
afs_target: "/afs/.openstack.org/project/tarballs.opendev.org/openstack/translation-source/{{ zuul.project.short_name}}/"
afs_target: "/afs/.openstack.org/project/tarballs.opendev.org/openstack/translation-source/{{ zuul.project.short_name }}/"
- name: Destroy AFS token
include_role:
name: destroy-afs-token


+ 1
- 1
playbooks/translation/upstream-translation-update.yaml View File

@ -5,7 +5,7 @@
tasks:
- name: Run upstream_translation_update.sh script
command: "{{ ansible_user_dir }}/scripts/upstream_translation_update.sh {{ zuul.project.short_name }} {{ zuul.job }} {{zuul.branch}} {{ ansible_user_dir }}/{{ zuul.projects['opendev.org/openstack/horizon'].src_dir }}"
command: "{{ ansible_user_dir }}/scripts/upstream_translation_update.sh {{ zuul.project.short_name }} {{ zuul.job }} {{ zuul.branch }} {{ ansible_user_dir }}/{{ zuul.projects['opendev.org/openstack/horizon'].src_dir }}"
args:
chdir: "{{ zuul.project.src_dir }}"


+ 3
- 3
roles/test-upload-logs/tasks/main.yaml View File

@ -9,7 +9,7 @@
- name: Create log directories
file:
path: "{{zuul_logserver_root}}/{{ zuul_log_path }}"
path: "{{ zuul_logserver_root }}/{{ zuul_log_path }}"
state: directory
recurse: yes
mode: 0775
@ -26,7 +26,7 @@
- name: Upload logs to log server
synchronize:
src: "{{ zuul.executor.log_root }}/"
dest: "{{zuul_logserver_root}}/{{ zuul_log_path }}/"
dest: "{{ zuul_logserver_root }}/{{ zuul_log_path }}/"
rsync_opts:
- "--exclude=job-output.txt"
- "--exclude=job-output.json"
@ -44,7 +44,7 @@
- name: Upload console log and json output
synchronize:
src: "{{ zuul.executor.log_root }}/{{ item }}.gz"
dest: "{{zuul_logserver_root}}/{{ zuul_log_path }}/{{ item }}.gz"
dest: "{{ zuul_logserver_root }}/{{ zuul_log_path }}/{{ item }}.gz"
verify_host: true
with_items:
- job-output.txt


+ 5
- 5
roles/use-cached-repos/tasks/main.yaml View File

@ -5,9 +5,9 @@
register: cached_repos
- name: Clone cached repo to workspace
command: "git clone /opt/git/{{ item.0.name }} {{ ansible_user_dir }}/{{ item.0.src_dir}}"
command: "git clone /opt/git/{{ item.0.name }} {{ ansible_user_dir }}/{{ item.0.src_dir }}"
args:
creates: "{{ ansible_user_dir }}/{{ item.0.src_dir}}"
creates: "{{ ansible_user_dir }}/{{ item.0.src_dir }}"
when: item.1.stat.exists
with_together:
- "{{ zuul.projects.values() | list }}"
@ -18,9 +18,9 @@
- skip_ansible_lint
- name: Clone upstream repo to workspace
command: "git clone https://{{ item.0.canonical_hostname }}/{{ item.0.name}} {{ ansible_user_dir }}/{{ item.0.src_dir}}"
command: "git clone https://{{ item.0.canonical_hostname }}/{{ item.0.name }} {{ ansible_user_dir }}/{{ item.0.src_dir }}"
args:
creates: "{{ ansible_user_dir }}/{{ item.0.src_dir}}"
creates: "{{ ansible_user_dir }}/{{ item.0.src_dir }}"
when: not item.1.stat.exists
with_together:
- "{{ zuul.projects.values() | list }}"
@ -34,7 +34,7 @@
# To be idempotent, remove origin only if it's found in the local list.
shell: "git remote -v | grep origin && git remote rm origin || true"
args:
chdir: "{{ ansible_user_dir }}/{{ item.src_dir}}"
chdir: "{{ ansible_user_dir }}/{{ item.src_dir }}"
with_items: "{{ zuul.projects.values() | list }}"
# ANSIBLE0006: git remote is not supported by ansible module
tags:


+ 12
- 0
tests/fake-ansible/library/zuul_return.py View File

@ -0,0 +1,12 @@
# This is a fake zuul_return to make ansible-lint happy
from ansible.module_utils.basic import AnsibleModule
def main():
return AnsibleModule(
argument_spec=dict(
data=dict(default=None),
path=dict(default=None, type=str),
file=dict(default=None, type=str),
)
)

+ 6
- 11
tox.ini View File

@ -10,8 +10,7 @@ basepython = python3
[testenv:linters]
whitelist_externals = bash
setenv =
ANSIBLE_LIBRARY= {envsitepackagesdir}/zuul/ansible/base/library
ANSIBLE_ACTION_PLUGINS = {envsitepackagesdir}/zuul/ansible/base/actiongeneral
ANSIBLE_LIBRARY= {toxinidir}/tests/fake-ansible
# NOTE(pabelanger): if you'd like to run tox -elinters locally,
# you'll need to export ANSIBLE_ROLES_PATH pointing to the required
# repos.
@ -27,13 +26,10 @@ setenv =
# Add dependencies here since other jobs use python2 and zuul requires
# python3.
deps =
# Zuul is required to supply the zuul ansible modules for ansible-lint
zuul
# Unfortunately pip doesn't do actual dependency resolution, so
# we need to manually ansible at the top level to the same as
# zuul requirements.txt
# Pin ansible to common version we use, otherwise ansible-lint
# would pull in latest version.
ansible>=2.7.0,<2.8
ansible-lint<4
ansible-lint>=4.2.0,<5
hacking>=2.0.0,<2.1.0
bashate>=0.2
commands =
@ -42,11 +38,10 @@ commands =
# Run some policy checks on zuul.d/projects.yaml
{toxinidir}/tools/zuul-projects-checks.py
# Ansible lint
# [ANSIBLE0012] Commands should not change things if nothing needs doing
bash -c "find playbooks -type f -regex '.*.ya?ml' -print0 | \
xargs -t -n1 -0 ansible-lint -xANSIBLE0012"
xargs -t -n1 -0 ansible-lint"
bash -c 'find roles -maxdepth 1 -mindepth 1 -type d -printf "%p/\n" | \
xargs -t -n1 ansible-lint -xANSIBLE0012'
xargs -t -n1 ansible-lint'
# Ansible Syntax Check
bash -c "find playbooks -type f -regex '.*.ya?ml' -exec \
ansible-playbook --syntax-check -i {toxinidir}/tests/inventory \


Loading…
Cancel
Save