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

Release hardlink + check mode #36

Merged
merged 6 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Check mode support added
  • Loading branch information
xanmanning committed Jul 25, 2020
commit d53102dda38f911b59a4638d6b87df17acb01aac
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ This role has been tested on Ansible 2.7.0+ against the following Linux Distribu
- Fedora 29
- Fedora 30
- Fedora 31
- Fedora 32
- openSUSE Leap 15
- Ubuntu 18.04 LTS
- Ubuntu 20.04 LTS

## Disclaimer

Expand Down
12 changes: 9 additions & 3 deletions tasks/build/configure-k3s-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
path: "/var/lib/rancher/k3s/server/node-token"
register: k3s_slurped_control_token
delegate_to: "{{ k3s_control_delegate }}"
when: k3s_control_token is not defined
when: k3s_control_token is not defined and not ansible_check_mode
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"

- name: Ensure NODE_TOKEN is formatted correctly for use in templates
set_fact:
k3s_control_token: "{{ k3s_slurped_control_token.content | b64decode }}"
when: k3s_control_token is not defined
when: k3s_control_token is not defined and not ansible_check_mode

- name: Ensure dummy NODE_TOKEN is defined for ansible_check_mode
set_fact:
k3s_control_token: "{{ k3s_control_delegate | to_uuid }}"
check_mode: false
when: k3s_control_token is not defined and ansible_check_mode

- name: Ensure k3s service unit file is present
template:
Expand Down Expand Up @@ -54,5 +60,5 @@
and kubectl_get_nodes_result.stdout.find("NotReady") == -1
retries: 30
delay: 20
when: k3s_control_node and not k3s_no_flannel
when: k3s_control_node and not k3s_no_flannel and not ansible_check_mode
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
4 changes: 4 additions & 0 deletions tasks/build/download-k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
set_fact:
k3s_arch: "{{ k3s_arch_lookup[ansible_architecture].arch }}"
k3s_arch_suffix: "{{ k3s_arch_lookup[ansible_architecture].suffix }}"
check_mode: false

- name: Ensure URLs are set as facts for downloading binaries
set_fact:
k3s_binary_url: "{{ k3s_github_download_url }}/{{ k3s_release_version }}/k3s{{ k3s_arch_suffix }}"
k3s_hash_url: "{{ k3s_github_download_url }}/{{ k3s_release_version }}/sha256sum-{{ k3s_arch }}.txt"
check_mode: false

- name: Ensure the k3s hashsum is downloaded
uri:
url: "{{ k3s_hash_url }}"
return_content: true
register: k3s_hash_sum_raw
check_mode: false

- name: Ensure sha256sum is set from hashsum variable
set_fact:
Expand All @@ -23,6 +26,7 @@
reject('search', 'images') |
first).split() | first }}"
changed_when: false
check_mode: false

- name: Ensure installation directory exists
file:
Expand Down
4 changes: 4 additions & 0 deletions tasks/build/get-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
- name: Ensure k3s_release_version is set to default if false
set_fact:
k3s_release_version: "{{ k3s_release_channel }}"
check_mode: false
when: k3s_release_version is defined and not k3s_release_version

- name: Ensure the default release channel is set
set_fact:
k3s_release_channel: "{{ k3s_release_version | default('stable') }}"
check_mode: false

- name: Get the latest release version from k3s.io
uri:
url: "{{ k3s_api_releases }}"
return_content: true
body_format: json
register: k3s_latest_release
check_mode: false

- name: Ensure the release version is set as a fact
set_fact:
k3s_release_version: "{{ item.latest }}"
loop: "{{ k3s_latest_release.json.data }}"
check_mode: false
when: item.name == k3s_release_channel
and item.type == "channel"
5 changes: 3 additions & 2 deletions tasks/build/install-k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
src: "{{ k3s_install_dir }}/k3s-{{ k3s_release_version }}"
dest: "{{ k3s_install_dir }}/k3s"
state: link
when: (k3s_control_node and k3s_controller_count | length == 1)
or (k3s_primary_control_node and k3s_controller_count | length > 1)
when: ((k3s_control_node and k3s_controller_count | length == 1)
or (k3s_primary_control_node and k3s_controller_count | length > 1)) and not ansible_check_mode
notify:
- restart k3s
become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}"
Expand Down Expand Up @@ -56,6 +56,7 @@
- kubectl
- crictl
- ctr
when: not ansible_check_mode
become: "{{ k3s_become_for_install_dir | ternary(true, false, k3s_become_for_all) }}"

- name: Ensure k3s control plane is started
Expand Down
4 changes: 4 additions & 0 deletions tasks/build/preconfigure-k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,27 @@
create: true
regexp: "^{{ item }} @@@ {{ hostvars[item].ansible_host | default(hostvars[item].ansible_fqdn) }}"
loop: "{{ play_hosts }}"
check_mode: false
when: hostvars[item].k3s_control_node is defined

- name: Delegate a master control plane node
block:
- name: Lookup control node from file
command: "grep '{{ 'P_True' if (k3s_controller_count | length > 1) else 'C_True' }}' /tmp/inventory.txt"
changed_when: false
check_mode: false
register: k3s_control_delegate_raw

- name: Ensure control node is delegated to for obtaining a token
set_fact:
k3s_control_delegate: "{{ k3s_control_delegate_raw.stdout.split(' @@@ ')[0] }}"
check_mode: false
when: k3s_control_delegate is not defined

- name: Ensure the control node address is registered in Ansible
set_fact:
k3s_control_node_address: "{{ hostvars[k3s_control_delegate].ansible_host | default(hostvars[k3s_control_delegate].ansible_fqdn) }}"
check_mode: false
when: k3s_control_node_address is not defined

when: k3s_control_node_address is not defined
Expand Down
1 change: 1 addition & 0 deletions tasks/teardown/drain-and-remove-nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
when: k3s_check_kubectl.stat.exists is defined
and k3s_check_kubectl.stat.exists
and k3s_control_delegate is defined
and not ansible_check_mode