Skip to content

Commit

Permalink
Fix FQCN lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Daemonslayer2048 committed Oct 2, 2023
1 parent a6f2a0b commit 9de6b30
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 65 deletions.
3 changes: 1 addition & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ warn_list:
- var-spacing
- var-naming
skip_list:
- experimental
- fqcn-builtins
- experimental
4 changes: 2 additions & 2 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[defaults]
nocows = True
roles_path = ./roles
inventory = ./inventory/my-cluster/hosts.ini
inventory = ./inventory/hosts.ini

remote_tmp = $HOME/.ansible/tmp
local_tmp = $HOME/.ansible/tmp
Expand All @@ -11,4 +11,4 @@ pipelining = True
host_key_checking = False
deprecation_warnings = False
callback_whitelist = profile_roles, timer
display_skipped_hosts = no
display_skipped_hosts = no
6 changes: 3 additions & 3 deletions roles/rke2_common/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---

- name: Restart systemd-sysctl
service:
ansible.builtin.service:
state: restarted
name: systemd-sysctl

- name: Restart rke2-server
service:
ansible.builtin.service:
state: restarted
name: rke2-server

- name: Restart rke2-agent
service:
ansible.builtin.service:
state: restarted
name: rke2-agent
25 changes: 14 additions & 11 deletions roles/rke2_common/tasks/calculate_rke2_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,66 @@
when: ( install_rke2_version is not defined ) or ( install_rke2_version | length == 0 )
block:
- name: Stop if the provided is not valid
fail:
ansible.builtin.fail:
msg: "Provided channel is not valid"
when: rke2_channel not in channels

- name: Get full version name url
uri:
ansible.builtin.uri:
url: https://update.rke2.io/v1-release/channels/{{ rke2_channel }}
follow_redirects: safe
remote_src: true
register: rke2_version_url

- name: Set full version name
shell: set -o pipefail && echo {{ rke2_version_url.url }} | sed -e 's|.*/||'
ansible.builtin.shell: set -o pipefail && echo {{ rke2_version_url.url }} | sed -e 's|.*/||'
register: rke2_full_version
changed_when: false
args:
executable: /usr/bin/bash

- name: Set rke2_full_version fact
set_fact:
ansible.builtin.set_fact:
rke2_full_version: "{{ rke2_full_version.stdout if ((install_rke2_version is not defined) or (install_rke2_version|length == 0)) else install_rke2_version }}" # yamllint disable-line rule:line-length

- name: Set dot version
shell: set -o pipefail && echo {{ rke2_full_version }} | /usr/bin/cut -d'+' -f1
ansible.builtin.shell:
cmd: set -o pipefail && echo {{ rke2_full_version }} | /usr/bin/cut -d'+' -f1
register: rke2_version_dot_tmp
changed_when: false
args:
executable: /usr/bin/bash

- name: Set rke2_version_dot fact
set_fact:
ansible.builtin.set_fact:
rke2_version_dot: "{{ rke2_version_dot_tmp.stdout }}"

- name: Set Maj.Min version
shell: set -o pipefail && echo {{ rke2_full_version }} | /bin/awk -F'.' '{ print $1"."$2 }' | sed "s|^v||g"
ansible.builtin.shell:
cmd: set -o pipefail && echo {{ rke2_full_version }} | /bin/awk -F'.' '{ print $1"."$2 }' | sed "s|^v||g"
register: rke2_version_majmin_tmp
changed_when: false
args:
executable: /usr/bin/bash

- name: Set rke2_version_majmin fact
set_fact:
ansible.builtin.set_fact:
rke2_version_majmin: "{{ rke2_version_majmin_tmp.stdout }}"

- name: Set RPM version
shell: set -o pipefail && echo {{ rke2_full_version }} | sed -E -e "s/[\+-]/~/g" | sed -E -e "s/v(.*)/\1/"
ansible.builtin.shell:
cmd: set -o pipefail && echo {{ rke2_full_version }} | sed -E -e "s/[\+-]/~/g" | sed -E -e "s/v(.*)/\1/"
register: rke2_version_rpm_tmp
changed_when: false
args:
executable: /usr/bin/bash

- name: Set rke2_version_rpm fact
set_fact:
ansible.builtin.set_fact:
rke2_version_rpm: "{{ rke2_version_rpm_tmp.stdout }}"

- name: Describe versions
debug:
ansible.builtin.debug:
msg:
- "Full version, with revision indication: {{ rke2_full_version }}"
- "Version without revision indication: {{ rke2_version_dot }}"
Expand Down
4 changes: 2 additions & 2 deletions roles/rke2_common/tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
changed_when: false

- name: Restart rke2-server if package installed and config changed or RKE2 version changed
service:
ansible.builtin.service:
state: restarted
name: rke2-server
when:
Expand All @@ -269,7 +269,7 @@
- (tmp_sha1 != previous_rke2_config.stat.checksum or (rke2_version_changed | default(false)))

- name: Restart rke2-agent if package installed and config changed or RKE2 version changed
service:
ansible.builtin.service:
state: restarted
name: rke2-agent
when:
Expand Down
8 changes: 4 additions & 4 deletions roles/rke2_common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
ansible.builtin.include_tasks: previous_install.yml

- name: Include images_tarball_install.yml
include_tasks: images_tarball_install.yml
ansible.builtin.include_tasks: images_tarball_install.yml

- name: "Check for binary tarball in tarball_install/rke2.linux-amd64.tar.gz"
stat:
ansible.builtin.stat:
path: "{{ playbook_dir }}/tarball_install/rke2.linux-amd64.tar.gz"
register: rke2_binary_tarball_check
delegate_to: 127.0.0.1
become: false

- name: Include calculate_rke2_version.yml
include_tasks: calculate_rke2_version.yml
ansible.builtin.include_tasks: calculate_rke2_version.yml
when: not rke2_binary_tarball_check.stat.exists

- name: SLES/Ubuntu/Tarball Installation
Expand All @@ -36,7 +36,7 @@
when:
- ansible_os_family == 'RedHat' or ansible_os_family == 'Rocky'
- not rke2_binary_tarball_check.stat.exists
include_tasks: rpm_install.yml
ansible.builtin.include_tasks: rpm_install.yml

# Disable Firewalld
# We recommend disabling firewalld. For Kubernetes 1.19+, firewalld must be turned off.
Expand Down
8 changes: 4 additions & 4 deletions roles/rke2_common/tasks/previous_install.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: Check if rke2-server is previously installed
ansible.builtin.ansible.builtin.debug:
ansible.builtin.debug:
msg: "rke2-server is already installed. Skipping installation steps."
when: >
ansible_facts.services["rke2-server.service"] is defined
Expand Down Expand Up @@ -29,19 +29,19 @@
and not ansible_facts.services["rke2-agent.service"].status == 'disabled'
- name: Check for the rke2 binary
stat:
ansible.builtin.stat:
path: /usr/local/bin/rke2
register: rke2_binary

- name: Get current RKE2 version if already installed
shell: set -o pipefail && /usr/local/bin/rke2 -v | head -n 1 | cut -d ' ' -f 3
ansible.builtin.shell: set -o pipefail && /usr/local/bin/rke2 -v | head -n 1 | cut -d ' ' -f 3
register: installed_rke2_version_tmp
changed_when: false
args:
executable: /usr/bin/bash
when: rke2_binary.stat.exists

- name: Determine if current version differs what what is being installed
set_fact:
ansible.builtin.set_fact:
installed_rke2_version: "{{installed_rke2_version_tmp.stdout}}"
when: rke2_binary.stat.exists
8 changes: 4 additions & 4 deletions roles/rke2_common/tasks/rpm_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Add RKE2 Common repo if it doesn't exist
- name: Add the rke2-common repo RHEL/CentOS/Rocky
yum_repository:
ansible.builtin.yum_repository:
name: "{{ rke2_common_yum_repo.name }}"
description: "{{ rke2_common_yum_repo.description }}"
baseurl: "{{ rke2_common_yum_repo.baseurl }}"
Expand All @@ -18,7 +18,7 @@
when: not stat_rke2_common_repo.stat.exists and ansible_lsb.major_release == '7'

- name: Add the rke2-common repo RHEL/CentOS 8
yum_repository:
ansible.builtin.yum_repository:
name: "{{ rke2_common_yum_repo.name }}"
description: "{{ rke2_common_yum_repo.description }}"
baseurl: "{{ rke2_common_yum_repo.baseurl }}"
Expand All @@ -29,13 +29,13 @@

# Does the Rancher RKE2 versioned repo exist already
- name: Check to see if rke2 versioned repo exists
stat:
ansible.builtin.stat:
path: '/etc/yum.repos.d/rke2-v{{ rke2_version_majmin }}.repo'
register: stat_rke2_versioned_repo

# Add RKE2 versioned repo if it doesn't exist
- name: Add the rke2 versioned repo CentOS/RHEL/Rocky
yum_repository:
ansible.builtin.yum_repository:
name: "{{ rke2_versioned_yum_repo.name }}"
description: "{{ rke2_versioned_yum_repo.description }}"
baseurl: "{{ rke2_versioned_yum_repo.baseurl }}"
Expand Down
24 changes: 12 additions & 12 deletions roles/rke2_common/tasks/tarball_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
when: rke2_binary_tarball_check.stat.exists

- name: Determine if current version differs what what is being installed
set_fact:
ansible.builtin.set_fact:
rke2_version_changed: true
when:
- not rke2_binary_tarball_check.stat.exists
- not installed or installed_rke2_version != rke2_full_version

- name: TARBALL | Download the tarball
get_url:
ansible.builtin.get_url:
url: https://github.com/rancher/rke2/releases/download/{{ rke2_full_version }}/rke2.linux-amd64.tar.gz
dest: "{{ temp_dir.path }}/rke2.linux-amd64.tar.gz"
mode: "0644"
Expand All @@ -41,7 +41,7 @@
- rke2_version_changed

- name: TARBALL | Install tar package
package:
ansible.builtin.package:
name: tar
state: present
ignore_errors: true # noqa ignore-errors
Expand All @@ -57,18 +57,18 @@
remote_src: true

- name: Get tarball RKE2 version from temp location
shell: set -o pipefail && {{ temp_dir.path }}/bin/rke2 -v | head -n 1 | cut -d ' ' -f 3
ansible.builtin.shell: set -o pipefail && {{ temp_dir.path }}/bin/rke2 -v | head -n 1 | cut -d ' ' -f 3
register: tarball_rke2_version_tmp
changed_when: false
args:
executable: /usr/bin/bash

- name: Set tarball RKE2 version var
set_fact:
ansible.builtin.set_fact:
tarball_rke2_version: "{{tarball_rke2_version_tmp.stdout}}"

- name: Determine if current version differs what what is being installed
set_fact:
ansible.builtin.set_fact:
rke2_version_changed: true
when:
- not installed or installed_rke2_version != tarball_rke2_version
Expand Down Expand Up @@ -126,7 +126,7 @@
replace: '{{ tarball_dir }}'

- name: TARBALL | Moving Systemd units to /etc/systemd/system
copy:
ansible.builtin.copy:
src: "{{ tarball_dir }}/lib/systemd/system/rke2-server.service"
dest: /etc/systemd/system/rke2-server.service
mode: '0644'
Expand All @@ -137,7 +137,7 @@
- inventory_hostname in groups['rke2_servers']

- name: TARBALL | Moving Systemd units to /etc/systemd/system
copy:
ansible.builtin.copy:
src: "{{ tarball_dir }}/lib/systemd/system/rke2-server.env"
dest: /etc/systemd/system/rke2-server.env
mode: '0644'
Expand All @@ -148,7 +148,7 @@
- inventory_hostname in groups['rke2_servers']

- name: TARBALL | Moving Systemd units to /etc/systemd/system
copy:
ansible.builtin.copy:
src: "{{ tarball_dir }}/lib/systemd/system/rke2-agent.service"
dest: /etc/systemd/system/rke2-agent.service
mode: '0644'
Expand All @@ -159,7 +159,7 @@
- inventory_hostname in groups.get('rke2_agents', [])

- name: TARBALL | Moving Systemd units to /etc/systemd/system
copy:
ansible.builtin.copy:
src: "{{ tarball_dir }}/lib/systemd/system/rke2-agent.env"
dest: /etc/systemd/system/rke2-agent.env
mode: '0644'
Expand All @@ -170,11 +170,11 @@
- inventory_hostname in groups.get('rke2_agents', [])

- name: TARBALL | Refreshing systemd unit files
systemd:
ansible.builtin.systemd:
daemon-reload: yes

- name: Remove the temp_dir
file:
ansible.builtin.file:
path: "{{ temp_dir.path }}"
state: absent
when: temp_dir.path is defined
2 changes: 1 addition & 1 deletion roles/rke2_server/tasks/first_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
changed_when: false

- name: Extract the hostname-override parameter from the kubelet process
set_fact:
ansible.builtin.set_fact:
kubelet_hostname_override_parameter: "{{ kubelet_check.stdout |\
regex_search('\\s--hostname-override=((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9]))\\s',\
'\\1') }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/rke2_server/tasks/other_servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
changed_when: false

- name: Extract the hostname-override parameter from the kubelet process
set_fact:
ansible.builtin.set_fact:
kubelet_hostname_override_parameter: "{{ kubelet_check.stdout |\
regex_search('\\s--hostname-override=((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9]))\\s',\
'\\1') }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/testing/tasks/basic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
register: test_is_selinux_true

- name: Assertions
assert:
ansible.builtin.assert:
that:
- test_rke2_config_file.stat.exists
- not test_is_selinux_true.failed
8 changes: 4 additions & 4 deletions roles/testing/tasks/kubectl_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


- name: Ensure kubelet process is present on host
command: >-
ansible.builtin.command: >-
ps -C kubelet -F -ww --no-headers
register: kubelet_check
until: kubelet_check.rc == 0
Expand All @@ -11,14 +11,14 @@
changed_when: false

- name: Extract the hostname-override parameter from the kubelet process # noqa jinja[spacing]
set_fact:
ansible.builtin.set_fact:
kubelet_hostname_override_parameter: "{{ kubelet_check.stdout |\
regex_search('\\s--hostname-override=((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9]))\\s',\
'\\1') }}"
changed_when: false

- name: Are all nodes in Ready state?
command: >-
ansible.builtin.command: >-
/var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml
--server https://127.0.0.1:6443 get no {{ kubelet_hostname_override_parameter[0] }}
-o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
Expand All @@ -30,6 +30,6 @@
changed_when: false

- name: Assertions
assert:
ansible.builtin.assert:
that:
- "'True' in status_result.stdout"
Loading

0 comments on commit 9de6b30

Please sign in to comment.