From 89e4760bf5fe7ebbfb1386a67923b8ea076dac4d Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Tue, 25 Jun 2024 20:53:28 -0400 Subject: [PATCH] Update Linting (#160) --- .ansible-lint | 9 ++-- .markdownlint.yml | 4 +- .pre-commit-config.yaml | 4 +- .yamllint | 24 +++++----- README.md | 2 +- examples/ee_builder_base.yaml | 10 ++--- examples/ee_venv_migrate.yaml | 6 +-- galaxy.yml | 44 +++++++++---------- meta/runtime.yml | 2 +- roles/ee_builder/defaults/main.yml | 4 +- roles/ee_builder/meta/main.yml | 1 - roles/ee_builder/tasks/00_build_ee.yml | 20 +++++---- roles/ee_builder/tasks/main.yml | 2 +- roles/ee_builder/vars/main.yml | 2 +- roles/virtualenv_migrate/defaults/main.yml | 4 +- roles/virtualenv_migrate/meta/main.yml | 1 - .../tasks/00_gather_custom_requirements.yml | 6 +-- roles/virtualenv_migrate/tasks/01_ee_diff.yml | 2 +- .../tasks/02_ee_list_create.yml | 2 +- 19 files changed, 72 insertions(+), 77 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index cc13f56..2b7af4b 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -5,20 +5,17 @@ # exclude_paths: # - roles/master_role_example/ exclude_paths: - - '.github/' - - 'roles/master_role_example/' - - 'changelogs/' + - .github/ + - roles/master_role_example/ + - changelogs/ parseable: true use_default_rules: true # https://github.com/ansible/ansible-lint/issues/808 # with verbosity set to 1, its dumping 'unknown file type messages' # verbosity: 1 skip_list: - - meta-runtime - var-naming[no-role-prefix] kinds: - - playbooks: "**/examples/*.{yml,yaml}" - - tasks: "**/examples/tasks/*.yml" - vars: "**/examples/vars/*.yml" - vars: "**/examples/**/*.yml" ... diff --git a/.markdownlint.yml b/.markdownlint.yml index eb1dcb8..ace084e 100644 --- a/.markdownlint.yml +++ b/.markdownlint.yml @@ -4,7 +4,7 @@ default: true # MD003/heading-style/header-style - Heading style # This will ensure that the heading format is consistent across all markdown files MD003: - style: "atx" + style: atx # MD013/line-length - Line length # Setting to false to match the yamllint setting @@ -17,5 +17,5 @@ MD0046: MD033: allowed_elements: - - "br" + - br ... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 28e7ec4..477c461 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,9 +15,9 @@ repos: - id: ansible-lint pass_filenames: false always_run: true - entry: "ansible-lint" + entry: ansible-lint args: - - "--profile=production" + - --profile=production - repo: https://github.com/DavidAnson/markdownlint-cli2 rev: v0.13.0 hooks: diff --git a/.yamllint b/.yamllint index ffd9642..4846eab 100644 --- a/.yamllint +++ b/.yamllint @@ -1,24 +1,28 @@ --- extends: default -ignore: | - changelogs - rules: # 80 chars should be enough, but don't fail if a line is longer line-length: disable - colons: - max-spaces-before: 0 - max-spaces-after: -1 - document-end: {present: true} + braces: + max-spaces-inside: 1 + colons: disable + comments: + min-spaces-from-content: 1 + comments-indentation: disable indentation: - level: error + level: warning # Require indentation https://redhat-cop.github.io/automation-good-practices/#_yaml_and_jinja2_syntax indent-sequences: true truthy: level: error # Allow only YAML 1.2 booleans https://redhat-cop.github.io/automation-good-practices/#_yaml_and_jinja2_syntax allowed-values: - - 'true' - - 'false' + - "true" + - "false" + octal-values: + forbid-implicit-octal: true + forbid-explicit-octal: true + # Enabling yamllint check based on PR #35 + document-end: enable ... diff --git a/README.md b/README.md index c3c7f52..ae2ea68 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Redhat Communities of Practice Execution Environment Utilities Collection [![pre-commit tests](https://github.com/redhat-cop/ee_utilities/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/redhat-cop/ee_utilities/actions/workflows/pre-commit.yml) -[![Run Test of EE utilities](https://github.com/redhat-cop/ee_utilities/actions/workflows/ci_testing.yaml/badge.svg)](https://github.com/redhat-cop/ee_utilities/actions/workflows/ci_testing.yaml) +[![Run Test of EE utilities](https://github.com/redhat-cop/ee_utilities/actions/workflows/ci_testing.yml/badge.svg)](https://github.com/redhat-cop/ee_utilities/actions/workflows/ci_testing.yml) [![Galaxy Release](https://github.com/redhat-cop/ee_utilities/actions/workflows/release.yml/badge.svg)](https://github.com/redhat-cop/ee_utilities/actions/workflows/release.yml) This ansible collection includes a number of roles which can be useful for managing Ansible Execution Environments. Using this collection, you'll be able to automate following tasks: diff --git a/examples/ee_builder_base.yaml b/examples/ee_builder_base.yaml index 7c34162..e28db04 100644 --- a/examples/ee_builder_base.yaml +++ b/examples/ee_builder_base.yaml @@ -2,12 +2,10 @@ - name: Playbook to create custom EE hosts: localhost gather_facts: false - collections: - - infra.ee_utilities vars: # For controller configuration definition ee_builder_dir_clean: false - builder_dir: "." + builder_dir: . ee_update_base_images: false ee_reg_credential: Automation Hub Container Registry ee_base_image: registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel9:latest @@ -27,9 +25,9 @@ - python-requests - python-pyyaml python: - - pytz # for schedule_rrule lookup plugin - - python-dateutil>=2.7.0 # schedule_rrule - - awxkit # For import and export modules + - pytz # for schedule_rrule lookup plugin + - python-dateutil>=2.7.0 # schedule_rrule + - awxkit # For import and export modules galaxy: collections: - name: awx.awx diff --git a/examples/ee_venv_migrate.yaml b/examples/ee_venv_migrate.yaml index 0912bcc..f5a1f48 100644 --- a/examples/ee_venv_migrate.yaml +++ b/examples/ee_venv_migrate.yaml @@ -2,8 +2,6 @@ - name: Playbook to create custom EE hosts: tower gather_facts: false - collections: - - infra.ee_utilities vars: venv_migrate_default_ee_url: registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel9:latest ee_collections: @@ -27,13 +25,13 @@ ee_ah_token: 4ab76668c4b2622ab1dfb7cbee7e6c9b8e62c0f5 ee_list: "{{ hostvars[groups['tower'][0]]['ee_list'] }}" tasks: - - name: Create EE ansible.builtin.include_role: name: infra.ee_utilities.ee_builder - - name: Export python virtual enviroment list to file # noqa template-instead-of-copy + - name: Export python virtual enviroment list to file # noqa template-instead-of-copy ansible.builtin.copy: content: "{{ ee_list | to_nice_yaml(width=50, explicit_start=True, explicit_end=True) }}" dest: venv_migrate_ee_python.yaml + mode: "0644" ... diff --git a/galaxy.yml b/galaxy.yml index 47c763c..1eea163 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -5,31 +5,31 @@ version: 3.1.3-devel description: A collection of utility roles for usage with Ansible Execution Enviroments readme: README.md authors: - - Sean Sullivan @sean-m-sullivan - - Anshul Behl @anshulbehl - - Tom Page @Tompage1994 - - David Danielsson @djdanielsson + - Sean Sullivan @sean-m-sullivan + - Anshul Behl @anshulbehl + - Tom Page @Tompage1994 + - David Danielsson @djdanielsson repository: https://github.com/redhat-cop/ee_utilities/ issues: https://github.com/redhat-cop/ee_utilities//issues build_ignore: - - galaxy.yml.j2 - - release.yml - - .github - - .markdownlint.yml - - .ansible-lint - - .yamllint.yml - - .pre-commit-config.yaml - - .gitignore - - .gitattributes + - galaxy.yml.j2 + - release.yml + - .github + - .markdownlint.yml + - .ansible-lint + - .yamllint.yml + - .pre-commit-config.yaml + - .gitignore + - .gitattributes license: - - GPL-3.0-or-later + - GPL-3.0-or-later tags: - - execution - - enviroments - - collection - - utilities - - utils - - infrastructure - - ee_utilities - - ee_utils + - execution + - enviroments + - collection + - utilities + - utils + - infrastructure + - ee_utilities + - ee_utils ... diff --git a/meta/runtime.yml b/meta/runtime.yml index cbf368b..d26157b 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,3 +1,3 @@ --- -requires_ansible: '>=2.14.0' +requires_ansible: ">=2.15.0" ... diff --git a/roles/ee_builder/defaults/main.yml b/roles/ee_builder/defaults/main.yml index 25b16dd..a0d7d43 100644 --- a/roles/ee_builder/defaults/main.yml +++ b/roles/ee_builder/defaults/main.yml @@ -3,7 +3,6 @@ ee_container_runtime: podman ee_version: 3 - ee_stream: "{% if ee_base_registry_username is defined %}downstream{% else %}upstream{% endif %}" # Image defaults @@ -16,11 +15,10 @@ ansible_cfg_file: ansible.cfg # Default EE list ee_list: [] - # Major section Options ee_build_options: "{{ __ee_dnf_fix[ee_stream] }}" ee_build_arg_defaults: - ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: '-vv' + ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: -vv # Controls ee_image_push: true diff --git a/roles/ee_builder/meta/main.yml b/roles/ee_builder/meta/main.yml index fa6bebe..32f9e3a 100644 --- a/roles/ee_builder/meta/main.yml +++ b/roles/ee_builder/meta/main.yml @@ -16,6 +16,5 @@ galaxy_info: - all galaxy_tags: [] - dependencies: [] ... diff --git a/roles/ee_builder/tasks/00_build_ee.yml b/roles/ee_builder/tasks/00_build_ee.yml index 90ef759..4275be1 100644 --- a/roles/ee_builder/tasks/00_build_ee.yml +++ b/roles/ee_builder/tasks/00_build_ee.yml @@ -18,10 +18,10 @@ - name: Copy files/folders to pull from for additional_build_files ansible.builtin.copy: - src: '{{ item }}' - dest: '{{ ee_builder_dir | default(build_dir.path) }}/{{ item }}' - mode: '0655' - loop: '{{ __execution_environment_definition.build_items }}' + src: "{{ item }}" + dest: "{{ ee_builder_dir | default(build_dir.path) }}/{{ item }}" + mode: "0655" + loop: "{{ __execution_environment_definition.build_items }}" when: - __execution_environment_definition.build_items is defined - __execution_environment_definition.build_items|length @@ -30,30 +30,32 @@ ansible.builtin.template: src: ansible.cfg.j2 dest: "{{ ee_builder_dir | default(build_dir.path) }}/ansible.cfg" - mode: '0644' + mode: "0644" when: ee_pull_collections_from_hub - name: Create EE definition file ansible.builtin.template: src: execution_environment.yml.j2 dest: "{{ ee_builder_dir | default(build_dir.path) }}/execution_environment.yml" - mode: '0644' + mode: "0644" when: not __execution_environment_definition.skip_generation | default(false) | bool - name: Run the Ansible Builder Program ansible.builtin.command: > ansible-builder build -f execution_environment.yml - -t {{ __execution_environment_definition.name | default( __execution_environment_definition.ee_name )}}{% if __execution_environment_definition.tag is defined %}:{{ __execution_environment_definition.tag }}{% endif %} --container-runtime={{ ee_container_runtime }} + -t {{ __execution_environment_definition.name | default(__execution_environment_definition.ee_name) }}{% if __execution_environment_definition.tag is defined + %}:{{ __execution_environment_definition.tag }}{% endif %} --container-runtime={{ ee_container_runtime }} {% if ee_prune_images %} --prune-images{% endif %} {% if ee_galaxy_keyring is defined %} --galaxy-keyring={{ ee_galaxy_keyring }}{% endif %} - {% if ee_galaxy_ignore_signature_status_code is defined %}{% for status_code in ee_galaxy_ignore_signature_status_code %} --galaxy-ignore-signature-status-code={{ status_code }}{% endfor %}{% endif %} + {% if ee_galaxy_ignore_signature_status_code is defined %}{% for status_code in ee_galaxy_ignore_signature_status_code %} --galaxy-ignore-signature-status-code={{ + status_code }}{% endfor %}{% endif %} {% if galaxy_required_valid_signature_count is defined %} --galaxy-required-valid-signature-count={{ galaxy_required_valid_signature_count }}{% endif %} {% if ee_container_policy is defined %} --container-policy={{ ee_container_policy }}{% endif %} --verbosity {{ ee_verbosity | default(0) }} args: chdir: "{{ ee_builder_dir | default(build_dir.path) }}/" - changed_when: true # these will always run and will always report "changed" otherwise + changed_when: true # these will always run and will always report "changed" otherwise - name: Push image to registry containers.podman.podman_image: diff --git a/roles/ee_builder/tasks/main.yml b/roles/ee_builder/tasks/main.yml index ebfb7c2..f0353c4 100644 --- a/roles/ee_builder/tasks/main.yml +++ b/roles/ee_builder/tasks/main.yml @@ -19,7 +19,7 @@ ansible.builtin.template: src: ee_controller.yaml.j2 dest: "{{ controller_ee.path }}/ee_controller.yaml" - mode: '0644' + mode: "0644" - name: Include templated variable ansible.builtin.include_vars: diff --git a/roles/ee_builder/vars/main.yml b/roles/ee_builder/vars/main.yml index 902ee4d..8579815 100644 --- a/roles/ee_builder/vars/main.yml +++ b/roles/ee_builder/vars/main.yml @@ -9,5 +9,5 @@ __ee_stream_images: __ee_dnf_fix: upstream: {} downstream: - package_manager_path: /usr/bin/microdnf # This is set because the default images and redhat images require microdnf + package_manager_path: /usr/bin/microdnf # This is set because the default images and redhat images require microdnf ... diff --git a/roles/virtualenv_migrate/defaults/main.yml b/roles/virtualenv_migrate/defaults/main.yml index ac0dfdb..8ea22e9 100644 --- a/roles/virtualenv_migrate/defaults/main.yml +++ b/roles/virtualenv_migrate/defaults/main.yml @@ -1,8 +1,8 @@ --- # defaults file for virtualenv_migrate venv_migrate_default_venv_paths: - - "/var/lib/awx/venv/ansible/" -venv_migrate_default_ee_url: "registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel9:latest" + - /var/lib/awx/venv/ansible/ +venv_migrate_default_ee_url: registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel9:latest venv_migrate_show_diff_with_default: false venv_migrate_registry_username: "{{ registry_username | default('') }}" venv_migrate_registry_password: "{{ registry_password | default('') }}" diff --git a/roles/virtualenv_migrate/meta/main.yml b/roles/virtualenv_migrate/meta/main.yml index c737583..d4dcf97 100644 --- a/roles/virtualenv_migrate/meta/main.yml +++ b/roles/virtualenv_migrate/meta/main.yml @@ -26,6 +26,5 @@ galaxy_info: - all galaxy_tags: [] - dependencies: [] ... diff --git a/roles/virtualenv_migrate/tasks/00_gather_custom_requirements.yml b/roles/virtualenv_migrate/tasks/00_gather_custom_requirements.yml index 466c424..e8a0bb6 100644 --- a/roles/virtualenv_migrate/tasks/00_gather_custom_requirements.yml +++ b/roles/virtualenv_migrate/tasks/00_gather_custom_requirements.yml @@ -2,7 +2,7 @@ - name: Gather | Get the list of custom virtualenvs ansible.builtin.command: awx-manage list_custom_venvs register: __venv_migrate_custom_venvs - changed_when: false # only gathering information + changed_when: false # only gathering information - name: Gather | Record all virtualenvs from AAP1.2 tower node ansible.builtin.set_fact: @@ -20,14 +20,14 @@ - not venv_migrate_show_diff_with_default - __venv_migrate_virtualenvs | length > 1 register: __venv_migrate_freeze_results - changed_when: false # only gathering information + changed_when: false # only gathering information - name: Gather pip freeze output from all venvs including the default venv ansible.builtin.command: "{{ item }}/bin/pip freeze" loop: "{{ __venv_migrate_virtualenvs }}" when: venv_migrate_show_diff_with_default | bool register: __venv_migrate_freeze_results_default - changed_when: false # only gathering information + changed_when: false # only gathering information - name: Gather results from pip_freeze based on conditions ansible.builtin.set_fact: diff --git a/roles/virtualenv_migrate/tasks/01_ee_diff.yml b/roles/virtualenv_migrate/tasks/01_ee_diff.yml index 156e394..a5c2649 100644 --- a/roles/virtualenv_migrate/tasks/01_ee_diff.yml +++ b/roles/virtualenv_migrate/tasks/01_ee_diff.yml @@ -9,7 +9,7 @@ password: "{{ venv_migrate_registry_password }}" - name: Diff | Get pip list from Default EE - ansible.builtin.command: "podman run --rm -it {{ venv_migrate_default_ee_url }} bash -c \"/bin/pip3 freeze\"" + ansible.builtin.command: podman run --rm -it {{ venv_migrate_default_ee_url }} bash -c "/bin/pip3 freeze" register: __venv_migrate_ee_pip_list_output changed_when: false diff --git a/roles/virtualenv_migrate/tasks/02_ee_list_create.yml b/roles/virtualenv_migrate/tasks/02_ee_list_create.yml index 578b93e..f6afc8b 100644 --- a/roles/virtualenv_migrate/tasks/02_ee_list_create.yml +++ b/roles/virtualenv_migrate/tasks/02_ee_list_create.yml @@ -6,7 +6,7 @@ - name: Create EE temp list ansible.builtin.set_fact: ee_list_temp: - - name: "{{ __venv_migrate_python_item.item | regex_replace('^\/|\/$', '') | regex_replace('\/|\/', '_') }}" + - name: "{{ __venv_migrate_python_item.item | regex_replace('^/|/$', '') | regex_replace('/|/', '_') }}" base_image: "{{ venv_migrate_default_ee_url }}" dependencies: galaxy: