From 7c3e47b5e22daa70fd9d93bbd9c8ffca1dc4938c Mon Sep 17 00:00:00 2001 From: Adam Leiner Date: Fri, 26 Jul 2024 17:42:44 -0400 Subject: [PATCH] linting 2 --- .ansible-lint | 3 +- roles/rke2/defaults/main.yml | 8 +-- .../rke2/tasks/add_ansible_managed_config.yml | 2 +- roles/rke2/tasks/add_manifest_addons.yml | 8 +-- roles/rke2/tasks/calculate_rke2_version.yml | 66 +++++++++---------- roles/rke2/tasks/check_node_ready.yml | 30 ++++----- roles/rke2/tasks/config.yml | 7 +- roles/rke2/tasks/first_server.yml | 18 ++--- roles/rke2/tasks/main.yml | 12 ++-- roles/rke2/tasks/other_nodes.yml | 12 ++-- roles/rke2/tasks/rpm_install.yml | 2 +- roles/rke2/tasks/save_generated_token.yml | 10 +-- 12 files changed, 87 insertions(+), 91 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index ba0c6d3..a90f5bf 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -8,4 +8,5 @@ warn_list: - var-naming - yaml[comments-indentation] skip_list: - - experimental \ No newline at end of file + - experimental + - yaml[line-length] \ No newline at end of file diff --git a/roles/rke2/defaults/main.yml b/roles/rke2/defaults/main.yml index 89059c1..e47a140 100644 --- a/roles/rke2/defaults/main.yml +++ b/roles/rke2/defaults/main.yml @@ -29,9 +29,9 @@ rke2_versioned_yum_repo: gpgcheck: true gpgkey: "https://rpm.rancher.io/public.key" enabled: yes -kubelet_node_name: +rke2_kubelet_node_name: - "nodeNameNotFound" rke2_config: {} -metrics_running: false -node_ready: "false" -api_server_running: false +rke2_metrics_running: false +rke2_node_ready: "false" +rke2_api_server_running: false diff --git a/roles/rke2/tasks/add_ansible_managed_config.yml b/roles/rke2/tasks/add_ansible_managed_config.yml index 09e8e2f..29103cd 100644 --- a/roles/rke2/tasks/add_ansible_managed_config.yml +++ b/roles/rke2/tasks/add_ansible_managed_config.yml @@ -33,5 +33,5 @@ path: "{{ file_destination }}" state: absent when: - - ansible_managed_check.changed | bool is false + - ansible_managed_check.changed | bool is false # noqa no-handler notify: "Restart {{ service_name }}" diff --git a/roles/rke2/tasks/add_manifest_addons.yml b/roles/rke2/tasks/add_manifest_addons.yml index 8397da8..e842197 100644 --- a/roles/rke2/tasks/add_manifest_addons.yml +++ b/roles/rke2/tasks/add_manifest_addons.yml @@ -8,7 +8,7 @@ - name: Create array of managed files ansible.builtin.set_fact: - managed_files: "{{local_files_find_return.files | map(attribute='path') | map('basename') }}" + managed_files: "{{ local_files_find_return.files | map(attribute='path') | map('basename') }}" - name: Add manifest addons files from localhost ansible.builtin.copy: @@ -19,17 +19,17 @@ group: root - name: Look up manifest files on remote - find: + ansible.builtin.find: paths: "{{ destination_directory }}" register: remote_files_find_return - name: Create array of remote files ansible.builtin.set_fact: - current_files: "{{remote_files_find_return.files | map(attribute='path') | map('basename') }}" + current_files: "{{ remote_files_find_return.files | map(attribute='path') | map('basename') }}" - name: Remove remote files not in managed files list ansible.builtin.file: path: "{{ destination_directory }}/{{ item }}" state: absent - with_items: "{{current_files}}" + with_items: "{{ current_files }}" when: item not in managed_files diff --git a/roles/rke2/tasks/calculate_rke2_version.yml b/roles/rke2/tasks/calculate_rke2_version.yml index 0010e92..12c0712 100644 --- a/roles/rke2/tasks/calculate_rke2_version.yml +++ b/roles/rke2/tasks/calculate_rke2_version.yml @@ -35,7 +35,7 @@ # - name: Set rke2_full_version fact # ansible.builtin.set_fact: - # rke2_full_version: "{{ rke2_full_version.stdout if (install_rke2_version | length == 0) else install_rke2_version }}" +# rke2_full_version: "{{ rke2_full_version.stdout if (install_rke2_version | length == 0) else install_rke2_version }}" - name: Set rke2_full_version fact from variable source ansible.builtin.set_fact: @@ -55,40 +55,40 @@ - rke2_full_version | length > 0 block: - - name: Set Maj.Min version - ansible.builtin.shell: - cmd: set -o pipefail && echo {{ rke2_full_version }} | /bin/awk -F'.' '{ print $1"."$2 }' | sed "s|^v||g" - register: rke2_version_majmin_tmp - changed_when: false - args: - executable: /usr/bin/bash + - name: Set Maj.Min version + ansible.builtin.shell: + cmd: set -o pipefail && echo {{ rke2_full_version }} | /bin/awk -F'.' '{ print $1"."$2 }' | sed "s|^v||g" + register: rke2_version_majmin_tmp + changed_when: false + args: + executable: /usr/bin/bash - - name: Set rke2_version_majmin fact - ansible.builtin.set_fact: - rke2_version_majmin: "{{ rke2_version_majmin_tmp.stdout }}" + - name: Set rke2_version_majmin fact + ansible.builtin.set_fact: + rke2_version_majmin: "{{ rke2_version_majmin_tmp.stdout }}" - - name: Set RPM version - ansible.builtin.shell: - cmd: set -o pipefail && echo {{ rke2_full_version }} | sed -E -e "s/[\+-]/~/g" | sed -E -e "s/v(.*)/\1/" - register: rke2_version_rpm_tmp - changed_when: false - args: - executable: /usr/bin/bash + - name: Set RPM version + ansible.builtin.shell: + cmd: set -o pipefail && echo {{ rke2_full_version }} | sed -E -e "s/[\+-]/~/g" | sed -E -e "s/v(.*)/\1/" + register: rke2_version_rpm_tmp + changed_when: false + args: + executable: /usr/bin/bash - - name: Set rke2_version_rpm fact - ansible.builtin.set_fact: - rke2_version_rpm: "{{ rke2_version_rpm_tmp.stdout }}" + - name: Set rke2_version_rpm fact + ansible.builtin.set_fact: + rke2_version_rpm: "{{ rke2_version_rpm_tmp.stdout }}" - - name: Prepend 'dash' to version string - ansible.builtin.set_fact: - rke2_version_rpm: "{{ '-' + rke2_version_rpm }}" - when: - - rke2_version_rpm | length > 0 + - name: Prepend 'dash' to version string + ansible.builtin.set_fact: + rke2_version_rpm: "{{ '-' + rke2_version_rpm }}" + when: + - rke2_version_rpm | length > 0 - # - name: Describe versions - # ansible.builtin.debug: - # msg: - # - "Full version, with revision indication: {{ rke2_full_version }}" - # # - "Version without revision indication: {{ rke2_version_dot }}" - # - "Major and Minor Only: {{ rke2_version_majmin }}" - # - "RPM Version (tilde): {{ rke2_version_rpm }}" + # - name: Describe versions + # ansible.builtin.debug: + # msg: + # - "Full version, with revision indication: {{ rke2_full_version }}" + # # - "Version without revision indication: {{ rke2_version_dot }}" + # - "Major and Minor Only: {{ rke2_version_majmin }}" + # - "RPM Version (tilde): {{ rke2_version_rpm }}" diff --git a/roles/rke2/tasks/check_node_ready.yml b/roles/rke2/tasks/check_node_ready.yml index 1ce68e3..e543852 100644 --- a/roles/rke2/tasks/check_node_ready.yml +++ b/roles/rke2/tasks/check_node_ready.yml @@ -8,18 +8,18 @@ timeout: "{{ check_node_ready_timeout }}" changed_when: false register: api_serve_status - ignore_errors: "{{check_node_ready_ignore_errors}}" + ignore_errors: "{{ check_node_ready_ignore_errors }}" - name: Set fact ansible.builtin.set_fact: - api_server_running: true + rke2_api_server_running: true when: - api_serve_status.state is not undefined - api_serve_status.state == "present" - name: Set fact ansible.builtin.set_fact: - api_server_running: "{{api_server_running}}" + rke2_api_server_running: "{{ rke2_api_server_running }}" - name: Get node_metrics ansible.builtin.uri: @@ -31,23 +31,21 @@ register: node_metrics retries: "{{ check_node_ready_retries }}" delay: "{{ check_node_ready_delay }}" - ignore_errors: "{{check_node_ready_ignore_errors}}" + ignore_errors: "{{ check_node_ready_ignore_errors }}" - name: Check that node_metrics collection was successful ansible.builtin.set_fact: - metrics_running: true + rke2_metrics_running: true when: - 200 | string in node_metrics.status | string -- name: Set fact for metrics_running +- name: Set fact for rke2_metrics_running ansible.builtin.set_fact: - metrics_running: "{{metrics_running}}" + rke2_metrics_running: "{{ rke2_metrics_running }}" - name: Extract the kubelet_node_name from node metrics ansible.builtin.set_fact: - kubelet_node_name: "{{ node_metrics.content | \ - regex_search('kubelet_node_name{node=\"(.*)\"}',\ - '\\1') }}" + kubelet_node_name: "{{ node_metrics.content | regex_search('kubelet_node_name{node=\"(.*)\"}', '\\1') }}" when: - 200 | string in node_metrics.status | string @@ -61,22 +59,22 @@ retries: "{{ check_node_ready_retries }}" delay: "{{ check_node_ready_delay }}" changed_when: false - ignore_errors: "{{check_node_ready_ignore_errors}}" + ignore_errors: "{{ check_node_ready_ignore_errors }}" - name: Set fact ansible.builtin.set_fact: - node_ready: "true" + rke2_node_ready: "true" when: - status_result.rc is not undefined - status_result.rc | string == "0" - name: Set fact ansible.builtin.set_fact: - node_ready: "{{node_ready}}" + rke2_node_ready: "{{ rke2_node_ready }}" - name: Node status ansible.builtin.debug: msg: | - "node_ready: {{node_ready}}" - "metrics_running: {{metrics_running}}" - "api_server_running: {{api_server_running}}" + "rke2_node_ready: {{ rke2_node_ready }}" + "rke2_metrics_running: {{ rke2_metrics_running }}" + "rke2_api_server_running: {{ rke2_api_server_running }}" diff --git a/roles/rke2/tasks/config.yml b/roles/rke2/tasks/config.yml index edff3b9..ace77c7 100644 --- a/roles/rke2/tasks/config.yml +++ b/roles/rke2/tasks/config.yml @@ -3,12 +3,12 @@ # combine host and group vars to form primary rke2_config - name: Combine host and group config vars ansible.builtin.set_fact: - temp_group_rke2_config: "{{cluster_rke2_config | default({}) | ansible.builtin.combine((group_rke2_config | default({})), list_merge='prepend_rp') }}" + temp_group_rke2_config: "{{ cluster_rke2_config | default({}) | ansible.builtin.combine((group_rke2_config | default({})), list_merge='prepend_rp') }}" # combine host and group vars to form primary rke2_config - name: Combine host and group config vars ansible.builtin.set_fact: - rke2_config: "{{temp_group_rke2_config | default({}) | ansible.builtin.combine((host_rke2_config | default({})), list_merge='prepend_rp') }}" + rke2_config: "{{ temp_group_rke2_config | default({}) | ansible.builtin.combine((host_rke2_config | default({})), list_merge='prepend_rp') }}" # write final config - name: Create config.yaml @@ -16,4 +16,5 @@ path: /etc/rancher/rke2/config.yaml block: "{{ rke2_config | to_nice_yaml(indent=0) }}" create: true - notify: Restart {{service_name}} + mode: "0640" + notify: Restart {{ service_name }} diff --git a/roles/rke2/tasks/first_server.yml b/roles/rke2/tasks/first_server.yml index facf649..c126799 100644 --- a/roles/rke2/tasks/first_server.yml +++ b/roles/rke2/tasks/first_server.yml @@ -12,13 +12,13 @@ enabled: true name: "{{ service_name }}" -- block: - - name: Start check_node_ready.yml - ansible.builtin.include_tasks: check_node_ready.yml - vars: - check_node_ready_timeout: 300 - check_node_ready_retries: 30 - check_node_ready_delay: 10 - check_node_ready_ignore_errors: false +- name: Check_node_ready any_errors_fatal: true - \ No newline at end of file + block: + - name: Start check_node_ready.yml + ansible.builtin.include_tasks: check_node_ready.yml + vars: + check_node_ready_timeout: 300 + check_node_ready_retries: 30 + check_node_ready_delay: 10 + check_node_ready_ignore_errors: false diff --git a/roles/rke2/tasks/main.yml b/roles/rke2/tasks/main.yml index f432392..07cdbc1 100644 --- a/roles/rke2/tasks/main.yml +++ b/roles/rke2/tasks/main.yml @@ -67,11 +67,7 @@ - name: Create a list of ready servers ansible.builtin.set_fact: - ready_servers: "{{ groups.rke2_servers| - map('extract', hostvars)| - selectattr('node_ready', 'equalto', true)| - map(attribute='inventory_hostname')| - list }}" + ready_servers: "{{ groups.rke2_servers | map('extract', hostvars) | selectattr('rke2_node_ready', 'equalto', true) | map(attribute='inventory_hostname') | list }}" delegate_to: localhost run_once: true @@ -108,7 +104,7 @@ - name: Save_generated_token.yml ansible.builtin.include_tasks: save_generated_token.yml vars: - token_source_node: "{{groups['rke2_servers'][0]}}" + token_source_node: "{{ groups['rke2_servers'][0] }}" when: - ready_servers | length == 0 @@ -116,7 +112,7 @@ - name: Save_generated_token.yml ansible.builtin.include_tasks: save_generated_token.yml vars: - token_source_node: "{{ready_servers[0]}}" + token_source_node: "{{ ready_servers[0] }}" when: - ready_servers | length > 0 @@ -131,7 +127,7 @@ - name: Include task file add_manifest_addons.yml ansible.builtin.include_tasks: add_manifest_addons.yml vars: - source_directory: "{{rke2_manifest_config_post_run_directory}}" + source_directory: "{{ rke2_manifest_config_post_run_directory }}" destination_directory: /var/lib/rancher/rke2/server/manifests/ansible_managed_1 when: - rke2_manifest_config_post_run_directory is defined diff --git a/roles/rke2/tasks/other_nodes.yml b/roles/rke2/tasks/other_nodes.yml index 9fdd3ad..1d004b0 100644 --- a/roles/rke2/tasks/other_nodes.yml +++ b/roles/rke2/tasks/other_nodes.yml @@ -8,11 +8,11 @@ timeout: "300" changed_when: false -- name: Include task file add-manifest-addons.yml - ansible.builtin.include_tasks: add-manifest-addons.yml - when: - - manifest_config_file_path is defined - - manifest_config_file_path | length > 0 +# - name: Include task file add-manifest-addons.yml +# ansible.builtin.include_tasks: add-manifest-addons.yml +# when: +# - manifest_config_file_path is defined +# - manifest_config_file_path | length > 0 - name: Generate config.yml on other nodes ansible.builtin.include_tasks: config.yml @@ -24,4 +24,4 @@ ansible.builtin.service: state: started enabled: true - name: "{{ service_name }}" \ No newline at end of file + name: "{{ service_name }}" diff --git a/roles/rke2/tasks/rpm_install.yml b/roles/rke2/tasks/rpm_install.yml index e9a4fd5..189d60d 100644 --- a/roles/rke2/tasks/rpm_install.yml +++ b/roles/rke2/tasks/rpm_install.yml @@ -27,7 +27,7 @@ - name: YUM-Based Install ansible.builtin.dnf: name: "{{ service_name }}{{ rke2_version_rpm }}" - state: "{{ rke2_package_state}}" + state: "{{ rke2_package_state }}" allow_downgrade: true register: result retries: 10 diff --git a/roles/rke2/tasks/save_generated_token.yml b/roles/rke2/tasks/save_generated_token.yml index fe5df4b..92400b4 100644 --- a/roles/rke2/tasks/save_generated_token.yml +++ b/roles/rke2/tasks/save_generated_token.yml @@ -3,18 +3,18 @@ - name: Wait for node-token ansible.builtin.wait_for: path: /var/lib/rancher/rke2/server/node-token - delegate_to: "{{token_source_node}}" + delegate_to: "{{ token_source_node }}" - name: Read node-token from master ansible.builtin.slurp: src: /var/lib/rancher/rke2/server/node-token register: node_token - delegate_to: "{{token_source_node}}" + delegate_to: "{{ token_source_node }}" - name: Store Master node-token ansible.builtin.set_fact: rke2_config_token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}" - delegate_to: "{{token_source_node}}" + delegate_to: "{{ token_source_node }}" - name: Set temp fact to store token config line ansible.builtin.set_fact: @@ -23,7 +23,7 @@ - name: Update host_rke2_config fact to contain server line ansible.builtin.set_fact: - host_rke2_config: "{{temp_token | default({}) | ansible.builtin.combine((host_rke2_config | default({})), list_merge='prepend_rp') }}" + host_rke2_config: "{{ temp_token | default({}) | ansible.builtin.combine((host_rke2_config | default({})), list_merge='prepend_rp') }}" - name: Set temp fact for api host ansible.builtin.set_fact: @@ -38,4 +38,4 @@ - name: Update host_rke2_config fact to contain server line ansible.builtin.set_fact: - host_rke2_config: "{{temp_host_rke2_config | default({}) | ansible.builtin.combine((host_rke2_config | default({})), list_merge='prepend_rp') }}" + host_rke2_config: "{{ temp_host_rke2_config | default({}) | ansible.builtin.combine((host_rke2_config | default({})), list_merge='prepend_rp') }}"