Skip to content

Commit

Permalink
linting round 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Leiner committed Jul 26, 2024
1 parent 41525c2 commit bd13dc8
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 67 deletions.
12 changes: 6 additions & 6 deletions roles/rke2/tasks/add_manifest_addons.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

- name: look up manifest files on localhost
find:
- name: Look up manifest files on localhost
ansible.builtin.find:
paths: "{{ source_directory }}"
register: local_files_find_return
delegate_to: localhost

- name: create array of managed files
- name: Create array of managed files
ansible.builtin.set_fact:
managed_files: "{{local_files_find_return.files | map(attribute='path') | map('basename') }}"

Expand All @@ -18,16 +18,16 @@
owner: root
group: root

- name: look up manifest files on remote
- name: Look up manifest files on remote
find:
paths: "{{ destination_directory }}"
register: remote_files_find_return

- name: create array of remote files
- name: Create array of remote files
ansible.builtin.set_fact:
current_files: "{{remote_files_find_return.files | map(attribute='path') | map('basename') }}"

- name: remove remote files not in managed files list
- name: Remove remote files not in managed files list
ansible.builtin.file:
path: "{{ destination_directory }}/{{ item }}"
state: absent
Expand Down
25 changes: 12 additions & 13 deletions roles/rke2/tasks/calculate_rke2_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@
args:
executable: /usr/bin/bash

# - name: Set rke2_full_version fact from internet source
# ansible.builtin.set_fact:
# rke2_full_version: "{{ rke2_full_version.stdout }}"
- name: Set rke2_full_version fact from internet source
ansible.builtin.set_fact:
rke2_full_version: "{{ rke2_full_version.stdout }}"

- name: Unset rke2_full_version if skipped
ansible.builtin.set_fact:
rke2_full_version: ""
when:
rke2_full_version is skipped

- name: Set rke2_full_version fact
ansible.builtin.set_fact:
rke2_full_version: "{{ rke2_full_version.stdout if ((install_rke2_version is not defined) or
(install_rke2_version | length == 0)) else install_rke2_version }}"

# - name: Set rke2_full_version fact from variable source
# - name: Set rke2_full_version fact
# ansible.builtin.set_fact:
# rke2_full_version: "{{ rke2_install_version }}"
# when:
# - rke2_install_version | length > 0
# 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:
rke2_full_version: "{{ rke2_install_version }}"
when:
- rke2_install_version | length > 0

- name: Set rke2_package_state to latest
ansible.builtin.set_fact:
Expand Down Expand Up @@ -83,7 +82,7 @@
ansible.builtin.set_fact:
rke2_version_rpm: "{{ '-' + rke2_version_rpm }}"
when:
- rke2_version_rpm | length > 0
- rke2_version_rpm | length > 0

# - name: Describe versions
# ansible.builtin.debug:
Expand Down
34 changes: 18 additions & 16 deletions roles/rke2/tasks/check_node_ready.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

- name: Wait for k8s apiserver
ansible.builtin.wait_for:
host: localhost
Expand All @@ -8,14 +10,14 @@
register: api_serve_status
ignore_errors: "{{check_node_ready_ignore_errors}}"

- name: set fact
- name: Set fact
ansible.builtin.set_fact:
api_server_running: true
when:
- api_serve_status.state is not undefined
- api_serve_status.state == "present"
when:
- api_serve_status.state is not undefined
- api_serve_status.state == "present"

- name: set fact
- name: Set fact
ansible.builtin.set_fact:
api_server_running: "{{api_server_running}}"

Expand All @@ -35,9 +37,9 @@
ansible.builtin.set_fact:
metrics_running: true
when:
- 200 | string in node_metrics.status | string
- 200 | string in node_metrics.status | string

- name: set fact for metrics_running
- name: Set fact for metrics_running
ansible.builtin.set_fact:
metrics_running: "{{metrics_running}}"

Expand All @@ -46,8 +48,8 @@
kubelet_node_name: "{{ node_metrics.content | \
regex_search('kubelet_node_name{node=\"(.*)\"}',\
'\\1') }}"
when:
- 200 | string in node_metrics.status | string
when:
- 200 | string in node_metrics.status | string

- name: Wait for node to show Ready status
ansible.builtin.command: >-
Expand All @@ -61,20 +63,20 @@
changed_when: false
ignore_errors: "{{check_node_ready_ignore_errors}}"

- name: set fact
- name: Set fact
ansible.builtin.set_fact:
node_ready: "true"
when:
- status_result.rc is not undefined
- status_result.rc | string == "0"
- status_result.rc is not undefined
- status_result.rc | string == "0"

- name: set fact
- name: Set fact
ansible.builtin.set_fact:
node_ready: "{{node_ready}}"

- name: node status
debug:
- name: Node status
ansible.builtin.debug:
msg: |
"node_ready: {{node_ready}}"
"metrics_running: {{metrics_running}}"
"api_server_running: {{api_server_running}}"
"api_server_running: {{api_server_running}}"
8 changes: 4 additions & 4 deletions roles/rke2/tasks/cis_hardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

- name: CIS MODE
become: yes
when:
- (cluster_rke2_config.profile | default("") | regex_search('^cis(-\\d+.\\d+)?$')) or
(group_rke2_config.profile | default("") | regex_search('^cis(-\\d+.\\d+)?$')) or
(host_rke2_config.profile | default("") | regex_search('^cis(-\\d+.\\d+)?$'))
when:
- (cluster_rke2_config.profile | default("") | regex_search('^cis(-\\d+.\\d+)?$')) or
(group_rke2_config.profile | default("") | regex_search('^cis(-\\d+.\\d+)?$')) or
(host_rke2_config.profile | default("") | regex_search('^cis(-\\d+.\\d+)?$'))
block:
- name: Create etcd group
ansible.builtin.group:
Expand Down
4 changes: 2 additions & 2 deletions roles/rke2/tasks/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

# combine host and group vars to form primary rke2_config
- name: combine host and group config vars
- 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') }}"

# combine host and group vars to form primary rke2_config
- name: combine host and group config vars
- 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') }}"

Expand Down
2 changes: 0 additions & 2 deletions roles/rke2/tasks/configure_rke2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@
file_path: "{{ rke2_pod_security_admission_config_file_path }}"
when:
- inventory_hostname in groups['rke2_servers']


5 changes: 3 additions & 2 deletions roles/rke2/tasks/first_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- name: Include task file config.yml
ansible.builtin.include_tasks: config.yml

- name: flush_handlers
- name: Flush_handlers
ansible.builtin.meta: flush_handlers

- block:
Expand All @@ -15,4 +15,5 @@
check_node_ready_retries: 30
check_node_ready_delay: 10
check_node_ready_ignore_errors: false
any_errors_fatal: true
any_errors_fatal: true

Check failure on line 19 in roles/rke2/tasks/first_server.yml

View workflow job for this annotation

GitHub Actions / Lint for push

19:3 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 19 in roles/rke2/tasks/first_server.yml

View workflow job for this annotation

GitHub Actions / Lint for push

19:1 [trailing-spaces] trailing spaces
20 changes: 8 additions & 12 deletions roles/rke2/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
- name: Has rke2 been installed already
ansible.builtin.include_tasks: previous_install.yml



- name: Check for images bundle
ansible.builtin.include_tasks: images_bundle.yml
when:
Expand All @@ -65,10 +63,10 @@
check_node_ready_delay: 2
check_node_ready_ignore_errors: true
when:
- inventory_hostname in groups['rke2_servers']
- inventory_hostname in groups['rke2_servers']

- name: Create a list of ready servers
set_fact:
ansible.builtin.set_fact:
ready_servers: "{{ groups.rke2_servers|
map('extract', hostvars)|
selectattr('node_ready', 'equalto', true)|
Expand All @@ -90,8 +88,6 @@
- name: Set rke2 configuration files
ansible.builtin.include_tasks: configure_rke2.yml



- name: Include task file add_manifest_addons.yml
ansible.builtin.include_tasks: add_manifest_addons.yml
vars:
Expand All @@ -106,23 +102,23 @@
- name: Start the first rke2 node
ansible.builtin.include_tasks: first_server.yml
when:
- inventory_hostname in groups['rke2_servers'][0]
- ready_servers | length == 0
- inventory_hostname in groups['rke2_servers'][0]
- ready_servers | length == 0

- name: save_generated_token.yml
- name: Save_generated_token.yml
ansible.builtin.include_tasks: save_generated_token.yml
vars:
token_source_node: "{{groups['rke2_servers'][0]}}"
when:
- ready_servers | length == 0
- 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 115 in roles/rke2/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

115:121 [line-length] line too long (141 > 120 characters)
- name: save_generated_token.yml
- name: Save_generated_token.yml
ansible.builtin.include_tasks: save_generated_token.yml
vars:
token_source_node: "{{ready_servers[0]}}"
when:
- ready_servers | length > 0
- ready_servers | length > 0

- name: Start all other rke2 nodes
ansible.builtin.include_tasks: other_nodes.yml
Expand Down
2 changes: 1 addition & 1 deletion roles/rke2/tasks/other_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
- name: Generate config.yml on other nodes
ansible.builtin.include_tasks: config.yml

- name: flush_handlers
- name: Flush_handlers
ansible.builtin.meta: flush_handlers
6 changes: 3 additions & 3 deletions roles/rke2/tasks/rpm_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
gpgkey: "{{ rke2_versioned_yum_repo.gpgkey }}"
enabled: "{{ rke2_versioned_yum_repo.enabled }}"

- name: debug install
debug:
msg: installing {{ service_name }}{{ rke2_version_rpm }}
# - name: Debug install
# ansible.builtin.debug:
# msg: installing {{ service_name }}{{ rke2_version_rpm }}

- name: YUM-Based Install
ansible.builtin.dnf:
Expand Down
6 changes: 3 additions & 3 deletions roles/rke2/tasks/save_generated_token.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

---

- name: Wait for node-token
ansible.builtin.wait_for:
Expand Down Expand Up @@ -30,14 +30,14 @@
temp_host_rke2_config:
server: "https://{{ rke2_kubernetes_api_server_host }}:9345"
when:
- rke2_kubernetes_api_server_host != ""
- rke2_kubernetes_api_server_host != ""

- name: Set temp fact to store server config line with server URL
ansible.builtin.set_fact:
temp_host_rke2_config:
server: "https://{{ token_source_node }}:9345"
when:
- rke2_kubernetes_api_server_host == ""
- rke2_kubernetes_api_server_host == ""

- name: Update host_rke2_config fact to contain server line
ansible.builtin.set_fact:
Expand Down
2 changes: 0 additions & 2 deletions roles/rke2/tasks/tarball_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
- rke2_install_tarball_url == ""
- not rke2_installed or rke2_installed_version != rke2_full_version



- name: Send provided tarball from local control machine if available
ansible.builtin.copy:
src: "{{ rke2_install_local_tarball_path }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/rke2/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ rke2_version_changed: false
rke2_reboot: false
rke2_version_majmin: ""
rke2_version_rpm: ""
rke2_package_state: "installed"
rke2_package_state: "installed"

0 comments on commit bd13dc8

Please sign in to comment.