Merge pull request #194 from PyratLabs/fix/linting

fix(linting): ensure tests pass
This commit is contained in:
Xan Manning 2022-09-02 18:08:49 +01:00 committed by GitHub
commit dae3eb928e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 58 additions and 48 deletions

View file

@ -188,11 +188,12 @@ configuration.
The below variables are used to change the way the role executes in Ansible,
particularly with regards to privilege escalation.
| Variable | Description | Default Value |
|-----------------------|----------------------------------------------------------------|---------------|
| `k3s_skip_validation` | Skip all tasks that validate configuration. | `false` |
| `k3s_skip_env_checks` | Skip all tasks that check environment configuration. | `false` |
| `k3s_become` | Escalate user privileges for tasks that need root permissions. | `false` |
| Variable | Description | Default Value |
|------------------------|----------------------------------------------------------------|---------------|
| `k3s_skip_validation` | Skip all tasks that validate configuration. | `false` |
| `k3s_skip_env_checks` | Skip all tasks that check environment configuration. | `false` |
| `k3s_skip_post_checks` | Skip all tasks that check post execution state. | `false` |
| `k3s_become` | Escalate user privileges for tasks that need root permissions. | `false` |
#### Important note about Python

View file

@ -38,6 +38,9 @@ k3s_skip_validation: false
# Skip all tasks that check environment configuration
k3s_skip_env_checks: false
# Skip post-checks
k3s_skip_post_checks: false
# Installation directory for k3s
k3s_install_dir: /usr/local/bin

View file

@ -1,17 +1,17 @@
---
- name: reload systemd
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
scope: "{{ k3s_systemd_context }}"
become: "{{ k3s_become }}"
- name: reload service
- name: Reload service
ansible.builtin.set_fact:
k3s_service_reloaded: true
become: "{{ k3s_become }}"
- name: restart k3s systemd
- name: Restart k3s systemd
ansible.builtin.systemd:
name: k3s
state: restarted
@ -25,7 +25,7 @@
- not ansible_check_mode
become: "{{ k3s_become }}"
- name: restart k3s service
- name: Restart k3s service
ansible.builtin.service:
name: k3s
state: restarted

View file

@ -23,7 +23,7 @@ scenario:
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}

View file

@ -23,7 +23,7 @@ scenario:
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}

View file

@ -23,7 +23,7 @@ scenario:
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}

View file

@ -23,7 +23,7 @@ scenario:
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}

View file

@ -13,6 +13,7 @@
node-ip: "{{ ansible_default_ipv4.address }}"
snapshotter: native
k3s_skip_validation: "{{ k3s_service_handler[ansible_service_mgr] == 'service' }}"
k3s_skip_post_checks: "{{ ansible_os_family | lower == 'redhat' }}"
pre_tasks:
- name: Set each node to be a control node
ansible.builtin.set_fact:

View file

@ -23,7 +23,7 @@ scenario:
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}

View file

@ -23,7 +23,7 @@ scenario:
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}

View file

@ -38,7 +38,7 @@
mode: 0600
become: "{{ k3s_become }}"
notify:
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- name: Ensure k3s service unit file is present
ansible.builtin.template:
@ -49,8 +49,8 @@
when:
- k3s_service_handler[ansible_service_mgr] == 'systemd'
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- name: Ensure k3s service file is present
ansible.builtin.template:
@ -60,8 +60,8 @@
when:
- k3s_service_handler[ansible_service_mgr] == 'service'
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure k3s logrotate file is present
@ -72,8 +72,8 @@
when:
- k3s_service_handler[ansible_service_mgr] == 'service'
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure k3s config file exists
@ -82,8 +82,8 @@
dest: "{{ k3s_config_file }}"
mode: 0644
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure secondary controllers are started
@ -93,10 +93,14 @@
- not k3s_primary_control_node
- import_tasks: post_checks_control_plane.yml
when: not k3s_skip_validation
when:
- not k3s_skip_validation
- not k3s_skip_post_checks
- name: Flush Handlers
ansible.builtin.meta: flush_handlers
- import_tasks: post_checks_nodes.yml
when: not k3s_skip_validation
when:
- not k3s_skip_validation
- not k3s_skip_post_checks

View file

@ -6,6 +6,6 @@
dest: "{{ k3s_config_dir }}/registries.yaml"
mode: 0600
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"

View file

@ -14,7 +14,7 @@
- ctr
when: not ansible_check_mode
notify:
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure k3s config file exists
@ -23,8 +23,8 @@
dest: "{{ k3s_config_file }}"
mode: 0644
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure cluster token is present when pre-defined
@ -43,7 +43,7 @@
mode: 0600
become: "{{ k3s_become }}"
notify:
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
when: k3s_control_token is defined
- name: Ensure k3s service unit file is present
@ -54,8 +54,8 @@
when:
- k3s_service_handler[ansible_service_mgr] == 'systemd'
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure k3s service file is present
@ -66,8 +66,8 @@
when:
- k3s_service_handler[ansible_service_mgr] == 'service'
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure k3s logrotate file is present
@ -78,8 +78,8 @@
when:
- k3s_service_handler[ansible_service_mgr] == 'service'
notify:
- "reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
- "Reload {{ k3s_service_handler[ansible_service_mgr] }}"
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
become: "{{ k3s_become }}"
- name: Ensure k3s killall script is present

View file

@ -24,7 +24,7 @@
- name: Ensure auto-deploying manifests are copied to the primary controller
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ k3s_server_manifests_dir }}/{{ item | basename | replace('.j2','') }}"
dest: "{{ k3s_server_manifests_dir }}/{{ item | basename | replace('.j2', '') }}"
mode: 0644
loop: "{{ k3s_server_manifests_templates }}"
become: "{{ k3s_become }}"
@ -46,7 +46,7 @@
- name: Ensure static pod manifests are copied to controllers
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ k3s_server_pod_manifests_dir }}/{{ item | basename | replace('.j2','') }}"
dest: "{{ k3s_server_pod_manifests_dir }}/{{ item | basename | replace('.j2', '') }}"
mode: 0644
loop: "{{ k3s_server_pod_manifests_templates }}"
become: "{{ k3s_become }}"

View file

@ -14,7 +14,7 @@
- name: Ensure configuration files are copied to controllers
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ k3s_config_yaml_d_dir }}/{{ item | basename | replace('.j2','') }}"
dest: "{{ k3s_config_yaml_d_dir }}/{{ item | basename | replace('.j2', '') }}"
mode: 0644
loop: "{{ k3s_server_config_yaml_d_files }}"
become: "{{ k3s_become }}"
@ -24,7 +24,7 @@
- name: Ensure configuration files are copied to agents
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ k3s_config_yaml_d_dir }}/{{ item | basename | replace('.j2','') }}"
dest: "{{ k3s_config_yaml_d_dir }}/{{ item | basename | replace('.j2', '') }}"
mode: 0644
loop: "{{ k3s_agent_config_yaml_d_files }}"
become: "{{ k3s_become }}"

View file

@ -30,7 +30,7 @@
- name: Ensure a count of control nodes is generated from ansible_play_hosts
ansible.builtin.set_fact:
k3s_controller_list: "{{ k3s_controller_list + [ item ] }}"
k3s_controller_list: "{{ k3s_controller_list + [item] }}"
when:
- hostvars[item].k3s_control_node is defined
- hostvars[item].k3s_control_node
@ -46,7 +46,7 @@
- name: Ensure a count of control nodes is generated
ansible.builtin.set_fact:
k3s_controller_list: "{{ k3s_controller_list + [ item ] }}"
k3s_controller_list: "{{ k3s_controller_list + [item] }}"
when:
- hostvars[item].k3s_control_node is defined
- hostvars[item].k3s_control_node

View file

@ -7,4 +7,6 @@
- import_tasks: ensure_uninstalled.yml
- import_tasks: post_checks_uninstalled.yml
when: not k3s_skip_validation
when:
- not k3s_skip_validation
- not k3s_skip_post_checks

View file

@ -64,10 +64,9 @@ k3s_github_download_url: "{{ k3s_github_url }}/releases/download"
# Generate a runtime config dictionary
k3s_runtime_config: "{{
(k3s_control_node is defined and k3s_control_node)
| ternary(
(k3s_server | default({})) | combine (k3s_agent | default({})),
| ternary((k3s_server | default({})) | combine(k3s_agent | default({})),
(k3s_agent | default({})),
(k3s_server | default({})) | combine (k3s_agent | default({})))
(k3s_server | default({})) | combine(k3s_agent | default({})))
}}"
# Determine if a cluster should be built