From af40f9ff8eac8ac7ecb2a29344362afb9db21f95 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 13 Jan 2021 17:11:03 +0000 Subject: [PATCH] Upgrade ansible-lint to 5.0 - remove role name rule as is included in newer versions - added .cache folder to git ignore (used by linter) - enabled optional yamllint run on ansible-lint - assured repository has a valid root requirements.yml (so linter can make use of it) - assured that we do not mix playbooks with non playbooks inside same folders - renamed undocumented "role" argument received by import_role to official "name". - added mocked roles/modules to avoid linter errors (ideally they should be provided by requiremetns.yml). Change-Id: I14b855f8a15afccaf4973e2a612aa7e9eae3bfa5 --- .ansible-lint | 55 +++++++++++++++++- .ansible-lint_rules/RoleNames.py | 57 ------------------- .gitignore | 1 + .pre-commit-config.yaml | 5 +- galaxy.yml | 0 requirements.yml | 1 + tripleo_ansible/ansible-role-requirements.yml | 3 + .../container_startup_config/converge.yml | 2 +- .../{ => files}/container-configs.yml | 0 .../playbooks/ceph_deactivate_mds.yaml | 2 +- tripleo_ansible/playbooks/cephadm.yml | 12 ++-- .../default/{ => vars}/mock_ceph_keys.yml | 0 .../{ => templates}/mock-hieradata.j2.yaml | 0 13 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 .ansible-lint_rules/RoleNames.py create mode 100644 galaxy.yml create mode 120000 requirements.yml rename tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/{ => files}/container-configs.yml (100%) rename tripleo_ansible/roles/tripleo_cephadm/molecule/default/{ => vars}/mock_ceph_keys.yml (100%) rename tripleo_ansible/roles/tripleo_hieradata/molecule/hieradata_vars/{ => templates}/mock-hieradata.j2.yaml (100%) diff --git a/.ansible-lint b/.ansible-lint index d566944ef..7bc09d710 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -5,5 +5,56 @@ quiet: false rulesdir: - .ansible-lint_rules/ verbosity: 1 -warn_list: - - '901' # Failed to load or parse file +# Mocking modules is not recommended as it prevents testing of invalid +# arguments or lack of their presence at runtime. It is preffered to +# make use of requirements.yml to declare them. +mock_roles: + - ceph-defaults + - ceph-facts +mock_modules: + - baremetal_nodes_validate + - baremetal_register_or_update_nodes + - ceph_key + - ceph_pool + - config_template + - container_startup_config + - lvm2_physical_devices_facts + - metalsmith_instances + - os_baremetal_clean_node + - os_baremetal_provide_node + - os_tripleo_baremetal_configure + - os_tripleo_baremetal_node_introspection + - podman_container + - podman_container_info + - podman_volume_info + - tripleo_baremetal_check_existing + - tripleo_baremetal_expand_roles + - tripleo_baremetal_populate_environment + - tripleo_build_heat_environment + - tripleo_composable_network + - tripleo_config_download + - tripleo_container_config_scripts + - tripleo_container_configs + - tripleo_container_image_prepare + - tripleo_derive_hci_parameters + - tripleo_diff_exec + - tripleo_fernet_keys_rotate + - tripleo_generate_ansible_inventory + - tripleo_generate_overcloudrc + - tripleo_get_flatten_stack + - tripleo_get_introspected_data + - tripleo_get_role_list + - tripleo_image_params_prepare + - tripleo_iptables + - tripleo_network_populate_environment + - tripleo_network_ports_populate_environment + - tripleo_os_net_config + - tripleo_os_net_config_mappings + - tripleo_overcloud_network_extract + - tripleo_overcloud_network_ports + - tripleo_passwords_rotate + - tripleo_plan_deploy + - tripleo_plan_parameters_update + - tripleo_swift_tempurl + - tripleo_templates_upload + - tripleo_unmanaged_populate_environment diff --git a/.ansible-lint_rules/RoleNames.py b/.ansible-lint_rules/RoleNames.py deleted file mode 100644 index a317e6bb1..000000000 --- a/.ansible-lint_rules/RoleNames.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) 2020 Gael Chamoulaud -# Copyright (c) 2020 Sorin Sbarnea -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -import re -from ansiblelint import AnsibleLintRule -ROLE_NAME_REGEX = '^[a-z][a-z0-9_]+$' - - -class RoleNames(AnsibleLintRule): - id = '710' - shortdesc = ( - "Role name {} does not match `%s` pattern" % ROLE_NAME_REGEX - ) - description = ( - "Role names are now limited to contain only lowercase alphanumeric " - "characters, plus '_' and start with an alpha character. See " - "`developing collections " - "`_" - ) - severity = 'HIGH' - done = [] # already noticed roles list - tags = ['metadata'] - version_added = 'v4.3.0' - - ROLE_NAME_REGEXP = re.compile(ROLE_NAME_REGEX) - - def match(self, file, text): - - path = file['path'].split("/") - if "roles" in path: - role_name = path[path.index("roles") + 1] - if role_name not in self.done: - self.done.append(role_name) - if not re.match(self.ROLE_NAME_REGEXP, role_name): - return self.shortdesc.format(role_name) - else: - return False - return False diff --git a/.gitignore b/.gitignore index 892535d7f..81072a12f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ doc/build/* # JetBrain .idea/ +.cache diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1cc62df1b..e9ab7ca19 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,12 +30,13 @@ repos: files: \.(yaml|yml)$ types: [file, yaml] entry: yamllint --strict -f parsable - - repo: https://github.com/ansible/ansible-lint - rev: v4.3.5 + - repo: https://github.com/ansible-community/ansible-lint + rev: v5.0.3 hooks: - id: ansible-lint additional_dependencies: - 'ansible<2.10' + - yamllint - repo: https://github.com/openstack-dev/bashate.git rev: 2.0.0 hooks: diff --git a/galaxy.yml b/galaxy.yml new file mode 100644 index 000000000..e69de29bb diff --git a/requirements.yml b/requirements.yml new file mode 120000 index 000000000..68eece9d4 --- /dev/null +++ b/requirements.yml @@ -0,0 +1 @@ +../tripleo-ansible/tripleo_ansible/requirements.yml \ No newline at end of file diff --git a/tripleo_ansible/ansible-role-requirements.yml b/tripleo_ansible/ansible-role-requirements.yml index e08242515..6afc25319 100644 --- a/tripleo_ansible/ansible-role-requirements.yml +++ b/tripleo_ansible/ansible-role-requirements.yml @@ -14,6 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. +# DEPRECATED, the official location for dependencies is now +# /requirements.yaml file. + - name: openstack-operations scm: git src: https://opendev.org/openstack/ansible-role-openstack-operations diff --git a/tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/converge.yml b/tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/converge.yml index 80f884fdd..5d5abae67 100644 --- a/tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/converge.yml +++ b/tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/converge.yml @@ -10,7 +10,7 @@ register: container_startup_config_tmp_dir - name: Generate container startup configs container_startup_config: - config_data: "{{ lookup('file', playbook_dir + '/container-configs.yml', errors='ignore') | default({}, True) | from_yaml }}" + config_data: "{{ lookup('file', playbook_dir + '/files/container-configs.yml', errors='ignore') | default({}, True) | from_yaml }}" config_base_dir: "{{ container_startup_config_tmp_dir.path }}" - name: Check that HAproxy container configuration file was created stat: diff --git a/tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/container-configs.yml b/tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/files/container-configs.yml similarity index 100% rename from tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/container-configs.yml rename to tripleo_ansible/ansible_plugins/tests/molecule/container_startup_config/files/container-configs.yml diff --git a/tripleo_ansible/playbooks/ceph_deactivate_mds.yaml b/tripleo_ansible/playbooks/ceph_deactivate_mds.yaml index 9bbdc3d5c..519c40996 100644 --- a/tripleo_ansible/playbooks/ceph_deactivate_mds.yaml +++ b/tripleo_ansible/playbooks/ceph_deactivate_mds.yaml @@ -18,7 +18,7 @@ hosts: all - name: upgrade ceph mdss cluster, deactivate all rank > 0 - hosts: "{{ groups[mon_group_name|default('mons')][0] }}" + hosts: "{{ groups[mon_group_name|default('mons')][0]|default([]) }}" become: true tasks: - name: deactivate all mds rank > 0 diff --git a/tripleo_ansible/playbooks/cephadm.yml b/tripleo_ansible/playbooks/cephadm.yml index 6e6e9bd30..c4d53fd86 100644 --- a/tripleo_ansible/playbooks/cephadm.yml +++ b/tripleo_ansible/playbooks/cephadm.yml @@ -18,31 +18,31 @@ tasks: - name: Satisfy Ceph prerequisites import_role: - role: tripleo_cephadm + name: tripleo_cephadm tasks_from: pre - name: Bootstrap Ceph import_role: - role: tripleo_cephadm + name: tripleo_cephadm tasks_from: bootstrap - name: Apply Ceph spec import_role: - role: tripleo_cephadm + name: tripleo_cephadm tasks_from: apply_spec when: not tripleo_cephadm_spec_on_bootstrap - name: Create Pools import_role: - role: tripleo_cephadm + name: tripleo_cephadm tasks_from: pools - name: Create Keys import_role: - role: tripleo_cephadm + name: tripleo_cephadm tasks_from: keys - name: Export configuration for tripleo_ceph_client import_role: - role: tripleo_cephadm + name: tripleo_cephadm tasks_from: export diff --git a/tripleo_ansible/roles/tripleo_cephadm/molecule/default/mock_ceph_keys.yml b/tripleo_ansible/roles/tripleo_cephadm/molecule/default/vars/mock_ceph_keys.yml similarity index 100% rename from tripleo_ansible/roles/tripleo_cephadm/molecule/default/mock_ceph_keys.yml rename to tripleo_ansible/roles/tripleo_cephadm/molecule/default/vars/mock_ceph_keys.yml diff --git a/tripleo_ansible/roles/tripleo_hieradata/molecule/hieradata_vars/mock-hieradata.j2.yaml b/tripleo_ansible/roles/tripleo_hieradata/molecule/hieradata_vars/templates/mock-hieradata.j2.yaml similarity index 100% rename from tripleo_ansible/roles/tripleo_hieradata/molecule/hieradata_vars/mock-hieradata.j2.yaml rename to tripleo_ansible/roles/tripleo_hieradata/molecule/hieradata_vars/templates/mock-hieradata.j2.yaml