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

Role is not re-entrant for HA mode #216

Open
weakcamel opened this issue Oct 31, 2023 · 2 comments
Open

Role is not re-entrant for HA mode #216

weakcamel opened this issue Oct 31, 2023 · 2 comments

Comments

@weakcamel
Copy link

Summary

This role can be run in several modes, including validation (installed, started, stopped, restarted, uninstalled, validated)

If you want to run it first in 'installed' and then 'validated' mode in single playbook, there is a problem with k3s_controller_list variable: on second run it contains duplicate entries and consequently validation fails. That's because Ansible - sadly - doesn't scope the variables properly and they're left behind as-is after a role finishes.

It's not a very common use case, however it would be nice if the role was re-entrant. It's also very easy to achieve - e.g. by setting the k3s_controller_list to an empty list

- name: Reset the value of k3s_controller_list
  ansible.builtin.set_fact:
    k3s_controller_list: []

just before it's being appended to in a loop:

- name: Ensure a count of control nodes is generated from ansible_play_hosts

Issue Type

  • Bug Report

Controller Environment and Configuration

Role version:

v3.4.2

Steps to Reproduce

---
- name: Set up K3s multinode cluster
  hosts: k3s
  become: true

  vars:
    ansible_become: true
  tasks:
    - name: Include K3s role
      ansible.builtin.import_role:
        name: xanmanning.k3s
      tags:
        - k3s

    - name: Switch k3s role to validation mode
      ansible.builtin.set_fact:
        k3s_state: validated
      tags:
        - k3s


    - name: Validate the k3s installation
      ansible.builtin.import_role:
        name: xanmanning.k3s
      tags:
        - k3s

Expected Result


Actual Result

TASK [xanmanning.k3s : Check the conditions when embedded etcd is defined] **********************************************************************************************************
skipping: [k3s-agent-1.lab.example.com]
skipping: [k3s-agent-2.lab.example.com]
skipping: [k3s-agent-3.lab.example.com]
fatal: [k3s-server-1.lab.example.com]: FAILED! => changed=false
  assertion: (((k3s_controller_list | length) % 2) == 1)
  evaluated_to: false
  msg: Etcd should have a minimum of 3 defined members and the number of members should be odd. Please see notes about HA in README.md
fatal: [k3s-server-2.lab.example.com]: FAILED! => changed=false
  assertion: (((k3s_controller_list | length) % 2) == 1)
  evaluated_to: false
  msg: Etcd should have a minimum of 3 defined members and the number of members should be odd. Please see notes about HA in README.md
fatal: [k3s-server-3.lab.example.com]: FAILED! => changed=false
  assertion: (((k3s_controller_list | length) % 2) == 1)
  evaluated_to: false
  msg: Etcd should have a minimum of 3 defined members and the number of members should be odd. Please see notes about HA in README.md

After adding an extra debug task to the role just before this one, I discovered:

ok: [k3s-agent-2.lab.example.com] =>
  k3s_controller_list:
  - k3s-server-1.lab.example.com
  - k3s-server-2.lab.example.com
  - k3s-server-3.lab.example.com
  - k3s-server-1.lab.example.com
  - k3s-server-2.lab.example.com
  - k3s-server-3.lab.example.com
  - ```
Copy link

stale bot commented Jan 19, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 19, 2024
@weakcamel
Copy link
Author

Still a problem

@stale stale bot removed the wontfix This will not be worked on label Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant