Skip to content

Commit

Permalink
Merge pull request #194 from PyratLabs/fix/linting
Browse files Browse the repository at this point in the history
fix(linting): ensure tests pass
  • Loading branch information
xanmanning committed Sep 2, 2022
2 parents d38f344 + 21fe3bc commit dae3eb9
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 48 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion molecule/autodeploy/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion molecule/debug/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion molecule/highavailabilitydb/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
1 change: 1 addition & 0 deletions molecule/highavailabilityetcd/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion molecule/highavailabilityetcd/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion molecule/nodeploy/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
26 changes: 15 additions & 11 deletions tasks/ensure_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions tasks/ensure_containerd_registries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
20 changes: 10 additions & 10 deletions tasks/ensure_installed_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tasks/ensure_k3s_auto_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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 }}"
Expand Down
4 changes: 2 additions & 2 deletions tasks/ensure_k3s_config_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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 }}"
Expand Down
4 changes: 2 additions & 2 deletions tasks/ensure_pre_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tasks/state_uninstalled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dae3eb9

Please sign in to comment.