Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(tests): Resolve Ansible Lint warnings and fix Molecule tests on GitHub Actions #202

Merged
merged 27 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f7be4a0
fix(ansible-lint): FQDN and `name`
dbrennand Mar 15, 2023
be30ded
fix(ansible-lint): add `name` and FQDN for module call
dbrennand Mar 15, 2023
2b5df13
fix(ansible-lint): add `name` to tasks and FQDN for module
dbrennand Mar 15, 2023
fe5c161
fix(ansible-lint): add task `name` and FQDN for module calls
dbrennand Mar 15, 2023
e629cc4
fix(ansible-lint): last `include_tasks`
dbrennand Mar 15, 2023
eda1405
fix(ansible-lint): add task names and FQDN
dbrennand Mar 15, 2023
47c1e36
refactor: `Ensure` to `Run`
dbrennand May 11, 2023
e99c32c
[skip ci]refactor: add exist and seperate ensure installed node task,…
dbrennand May 12, 2023
4d3ecbb
[skip ci]refactor: Pipe seperator
dbrennand May 12, 2023
a03dea9
[skip ci]refactor: run
dbrennand May 12, 2023
8ae72b0
refactor: remove quotes as other files don't use them
dbrennand May 12, 2023
963a6fb
[skip ci]refactor: task names, use `Run`
dbrennand May 12, 2023
6a0eab9
[skip ci]refactor: use variable name in task name
dbrennand May 12, 2023
2344625
[skip ci]refactor: task names
dbrennand May 12, 2023
7f6ad15
[skip ci]refactor: add service mgr in task name
dbrennand May 12, 2023
0333bdb
[skip ci]refactor: add task names and module FQDNs
dbrennand May 12, 2023
7f3c574
[skip ci]refactor: fix task name
dbrennand May 12, 2023
c186596
[skip ci]refactor: add -
dbrennand May 12, 2023
8d680d4
[skip ci]refactor: include task names and FQDNs
dbrennand May 12, 2023
ae392a3
[skip ci]refactor: add task names and FQDNs
dbrennand May 12, 2023
26fc6e5
[skip ci]: ignore `name[template]`
dbrennand May 12, 2023
38b6edf
refactor: `when` clause for `block` should be before `block`
dbrennand May 12, 2023
976d551
fix: https://github.com/ansible-community/molecule/issues/3883
dbrennand May 12, 2023
f176ea4
refactor: molecule lint command was removed in version `5.0.0`
dbrennand May 12, 2023
b854139
[skip ci]refactor: noqa for command tasks
dbrennand May 12, 2023
3258d30
refactor: use Ubuntu 22.04
dbrennand May 12, 2023
90891d9
Merge branch 'PyratLabs:main' into fix/ansible-lint
dbrennand May 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

skip_list:
- role-name
- name[template]
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,32 @@ defaults:
working-directory: "xanmanning.k3s"

jobs:
ansible-lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@v2
with:
path: "xanmanning.k3s"

- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install test dependencies
run: pip3 install -r molecule/lint-requirements.txt

- name: Run yamllint
run: yamllint -s .

- name: Run ansible-lint
run: ansible-lint --exclude molecule/ --exclude meta/

molecule:
name: Molecule
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
onedr0p marked this conversation as resolved.
Show resolved Hide resolved
strategy:
fail-fast: false
matrix:
Expand Down
5 changes: 0 additions & 5 deletions molecule/autodeploy/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ driver:
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
Expand All @@ -20,10 +19,6 @@ scenario:
- verify
- cleanup
- destroy
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}
Expand Down
5 changes: 0 additions & 5 deletions molecule/debug/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ driver:
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
Expand All @@ -20,10 +19,6 @@ scenario:
- verify
- cleanup
- destroy
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}
Expand Down
5 changes: 0 additions & 5 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ driver:
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
Expand All @@ -20,10 +19,6 @@ scenario:
- verify
- cleanup
- destroy
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}
Expand Down
5 changes: 0 additions & 5 deletions molecule/highavailabilitydb/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ driver:
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
Expand All @@ -20,10 +19,6 @@ scenario:
- verify
- cleanup
- destroy
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}
Expand Down
5 changes: 0 additions & 5 deletions molecule/highavailabilityetcd/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ driver:
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
Expand All @@ -20,10 +19,6 @@ scenario:
- verify
- cleanup
- destroy
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}
Expand Down
4 changes: 4 additions & 0 deletions molecule/lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r ../requirements.txt

yamllint>=1.25.0
ansible-lint>=4.3.5
5 changes: 0 additions & 5 deletions molecule/nodeploy/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ driver:
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
Expand All @@ -20,10 +19,6 @@ scenario:
- verify
- cleanup
- destroy
lint: |
set -e
yamllint -s .
ansible-lint --exclude molecule/ --exclude meta/
platforms:
- name: node1
image: ${MOLECULE_DISTRO:-"geerlingguy/docker-rockylinux8-ansible:latest"}
Expand Down
4 changes: 1 addition & 3 deletions molecule/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-r ../requirements.txt

molecule[docker]>=3.2
molecule-plugins[docker]
docker>=4.3.1
yamllint>=1.25.0
ansible-lint>=4.3.5
8 changes: 5 additions & 3 deletions tasks/ensure_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@
become: "{{ k3s_become }}"

- name: Ensure secondary controllers are started
include_tasks: ensure_control_plane_started_{{ ansible_service_mgr }}.yml
ansible.builtin.include_tasks: ensure_control_plane_started_{{ ansible_service_mgr }}.yml
when:
- k3s_control_node
- not k3s_primary_control_node

- import_tasks: post_checks_control_plane.yml
- name: Run control plane post checks
ansible.builtin.import_tasks: post_checks_control_plane.yml
when:
- not k3s_skip_validation
- not k3s_skip_post_checks

- name: Flush Handlers
ansible.builtin.meta: flush_handlers

- import_tasks: post_checks_nodes.yml
- name: Run node post checks
ansible.builtin.import_tasks: post_checks_nodes.yml
when:
- not k3s_skip_validation
- not k3s_skip_post_checks
16 changes: 7 additions & 9 deletions tasks/ensure_drain_and_remove_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
become: "{{ k3s_become }}"

- name: Clean up nodes that are in an uninstalled state
when:
- k3s_check_kubectl.stat.exists is defined
- k3s_check_kubectl.stat.exists
- k3s_control_delegate is defined
- not ansible_check_mode
block:

- name: Gather a list of nodes
ansible.builtin.command:
cmd: "{{ k3s_install_dir }}/kubectl get nodes"
Expand All @@ -19,7 +23,7 @@
register: kubectl_get_nodes_result
become: "{{ k3s_become }}"

- name: Ensure uninstalled nodes are drained
- name: Ensure uninstalled nodes are drained # noqa no-changed-when
ansible.builtin.command:
cmd: >-
{{ k3s_install_dir }}/kubectl drain {{ item }}
Expand All @@ -36,7 +40,7 @@
loop: "{{ ansible_play_hosts }}"
become: "{{ k3s_become }}"

- name: Ensure uninstalled nodes are removed
- name: Ensure uninstalled nodes are removed # noqa no-changed-when
ansible.builtin.command:
cmd: "{{ k3s_install_dir }}/kubectl delete node {{ item }}"
delegate_to: "{{ k3s_control_delegate }}"
Expand All @@ -48,9 +52,3 @@
- hostvars[item].k3s_state == 'uninstalled'
loop: "{{ ansible_play_hosts }}"
become: "{{ k3s_become }}"

when:
- k3s_check_kubectl.stat.exists is defined
- k3s_check_kubectl.stat.exists
- k3s_control_delegate is defined
- not ansible_check_mode
12 changes: 8 additions & 4 deletions tasks/ensure_installed.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---

- include_tasks: ensure_directories.yml
- name: Ensure directories exist
ansible.builtin.include_tasks: ensure_directories.yml
loop: "{{ k3s_ensure_directories_exist }}"
loop_control:
loop_var: directory

- include_tasks: ensure_installed_node.yml
- name: Ensure installed node
ansible.builtin.include_tasks: ensure_installed_node.yml
when:
- ((k3s_control_node and k3s_controller_list | length == 1)
or (k3s_primary_control_node and k3s_controller_list | length > 1))
Expand All @@ -14,15 +16,17 @@
- name: Flush Handlers
ansible.builtin.meta: flush_handlers

- include_tasks: ensure_installed_node.yml
- name: Ensure installed node | k3s_build_cluster
ansible.builtin.include_tasks: ensure_installed_node.yml
when: k3s_build_cluster

- name: Determine if the systems are already clustered
ansible.builtin.stat:
path: "{{ k3s_token_location }}"
register: k3s_token_cluster_check

- include_tasks: ensure_control_plane_started_{{ ansible_service_mgr }}.yml
- name: Ensure control plane started with {{ ansible_service_mgr }}
ansible.builtin.include_tasks: ensure_control_plane_started_{{ ansible_service_mgr }}.yml
when: (k3s_control_node and k3s_controller_list | length == 1)
or (k3s_primary_control_node and k3s_controller_list | length > 1)
or k3s_token_cluster_check.stat.exists
2 changes: 1 addition & 1 deletion tasks/ensure_installed_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
become: "{{ k3s_become }}"

- name: Ensure cluster token is present when pre-defined
when: k3s_control_token is defined
block:
- name: Ensure the cluster token file location exists
ansible.builtin.file:
Expand All @@ -44,7 +45,6 @@
become: "{{ k3s_become }}"
notify:
- "Restart k3s {{ k3s_service_handler[ansible_service_mgr] }}"
when: k3s_control_token is defined

- name: Ensure k3s service unit file is present
ansible.builtin.template:
Expand Down
15 changes: 6 additions & 9 deletions tasks/ensure_pre_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
loop: "{{ ansible_play_hosts }}"

- name: Ensure a k3s control node is defined if none are found in ansible_play_hosts
when:
- k3s_controller_list | length < 1
- k3s_build_cluster is defined
- k3s_build_cluster
block:

- name: Set the control host
ansible.builtin.set_fact:
k3s_control_node: true
Expand All @@ -52,11 +55,6 @@
- hostvars[item].k3s_control_node
loop: "{{ ansible_play_hosts }}"

when:
- k3s_controller_list | length < 1
- k3s_build_cluster is defined
- k3s_build_cluster

- name: Ensure a primary k3s control node is defined if multiple are found in ansible_play_hosts
ansible.builtin.set_fact:
k3s_primary_control_node: true
Expand Down Expand Up @@ -88,6 +86,8 @@
when: k3s_control_node is defined

- name: Delegate an initializing control plane node
when: k3s_registration_address is not defined
or k3s_control_delegate is not defined
block:
- name: Lookup control node from file
ansible.builtin.command:
Expand Down Expand Up @@ -124,6 +124,3 @@
when:
- k3s_registration_address is not defined
- k3s_control_node_address is not defined

when: k3s_registration_address is not defined
or k3s_control_delegate is not defined
2 changes: 1 addition & 1 deletion tasks/ensure_stopped.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
when: k3s_non_root is not defined or not k3s_non_root
become: "{{ k3s_become }}"

- name: Ensure k3s service is started
- name: Ensure k3s service is stopped
ansible.builtin.systemd:
name: k3s
state: stopped
Expand Down
6 changes: 4 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---

- import_tasks: pre_checks.yml
- name: Run pre-checks
ansible.builtin.import_tasks: pre_checks.yml

- include_tasks: state_{{ (k3s_state | lower) | default('installed') }}.yml
- name: Ensure state {{ (k3s_state | lower) | default('installed') }}
ansible.builtin.include_tasks: state_{{ (k3s_state | lower) | default('installed') }}.yml
Loading