Skip to content

Commit

Permalink
linting 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Leiner committed Jul 26, 2024
1 parent ee61292 commit 7c3e47b
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ warn_list:
- var-naming
- yaml[comments-indentation]
skip_list:
- experimental
- experimental
- yaml[line-length]
8 changes: 4 additions & 4 deletions roles/rke2/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion roles/rke2/tasks/add_ansible_managed_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
8 changes: 4 additions & 4 deletions roles/rke2/tasks/add_manifest_addons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
66 changes: 33 additions & 33 deletions roles/rke2/tasks/calculate_rke2_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}"
30 changes: 14 additions & 16 deletions roles/rke2/tasks/check_node_ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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 }}"
7 changes: 4 additions & 3 deletions roles/rke2/tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
# 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
ansible.builtin.blockinfile:
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 }}
18 changes: 9 additions & 9 deletions roles/rke2/tasks/first_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
12 changes: 4 additions & 8 deletions roles/rke2/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

Check warning on line 70 in roles/rke2/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

70:121 [line-length] line too long (167 > 120 characters)
delegate_to: localhost
run_once: true

Expand Down Expand Up @@ -108,15 +104,15 @@
- 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

# is the ready_servers array is > 0, we assume it's an established cluster and treat all nodes equally (no need for initial server procedure)

Check warning on line 111 in roles/rke2/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

111:121 [line-length] line too long (141 > 120 characters)
- 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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions roles/rke2/tasks/other_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,4 +24,4 @@
ansible.builtin.service:
state: started
enabled: true
name: "{{ service_name }}"
name: "{{ service_name }}"
2 changes: 1 addition & 1 deletion roles/rke2/tasks/rpm_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions roles/rke2/tasks/save_generated_token.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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') }}"

Check warning on line 26 in roles/rke2/tasks/save_generated_token.yml

View workflow job for this annotation

GitHub Actions / Lint for push

26:121 [line-length] line too long (139 > 120 characters)

- name: Set temp fact for api host
ansible.builtin.set_fact:
Expand All @@ -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') }}"

Check warning on line 41 in roles/rke2/tasks/save_generated_token.yml

View workflow job for this annotation

GitHub Actions / Lint for push

41:121 [line-length] line too long (150 > 120 characters)

0 comments on commit 7c3e47b

Please sign in to comment.