mirror of
https://github.com/techno-tim/k3s-ansible.git
synced 2026-10-23 12:12:04 +02:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b994f7479 | ||
|
|
8fb1e26c63 | ||
|
|
ee3a4a126e | ||
|
|
24054385e4 |
No files matched your search
@@ -26,7 +26,7 @@ if grep -Fq -- "node-role.kubernetes.io/master=true' -o=jsonpath" "$main_tasks";
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
grep -Fq -- "map('extract', hostvars, 'ansible_hostname')" "$main_tasks"
|
grep -Fq -- "map('extract', hostvars, ['ansible_facts', 'hostname'])" "$main_tasks"
|
||||||
grep -Fq -- 'difference(nodes.stdout.split())' "$main_tasks"
|
grep -Fq -- 'difference(nodes.stdout.split())' "$main_tasks"
|
||||||
grep -Fq -- 'crd/addons.k3s.cattle.io' "$main_tasks"
|
grep -Fq -- 'crd/addons.k3s.cattle.io' "$main_tasks"
|
||||||
grep -Fq -- 'crd/helmcharts.helm.cattle.io' "$main_tasks"
|
grep -Fq -- 'crd/helmcharts.helm.cattle.io' "$main_tasks"
|
||||||
|
|||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
repo_root="$(git rev-parse --show-toplevel)"
|
||||||
|
tasks_file="$repo_root/roles/raspberrypi/tasks/main.yml"
|
||||||
|
|
||||||
|
if [ ! -f "$tasks_file" ]; then
|
||||||
|
printf 'cannot find %s\n' "$tasks_file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The role decides whether a host is a Raspberry Pi from the return code of two
|
||||||
|
# ansible.builtin.command probes. The command module never executes under
|
||||||
|
# --check: it returns rc 0 with "Command would have run if not in check mode".
|
||||||
|
# Without check_mode: false on both probes every host looks like a Raspberry Pi
|
||||||
|
# in a check run, so distro specific tasks (e.g. the Ubuntu cgroup
|
||||||
|
# cmdline.txt edit) run against hosts that must not be touched.
|
||||||
|
probe_count="$(grep -c -- 'check_mode: false' "$tasks_file" || true)"
|
||||||
|
if [ "$probe_count" -lt 2 ]; then
|
||||||
|
printf 'raspberrypi detection probes must set check_mode: false (found %s, expected 2)\n' \
|
||||||
|
"$probe_count" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Both probes must be the detection greps, not some other task.
|
||||||
|
for probe in \
|
||||||
|
'grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo' \
|
||||||
|
'grep -E "Raspberry Pi" /proc/device-tree/model'; do
|
||||||
|
grep -Fq -- "$probe" "$tasks_file" || {
|
||||||
|
printf 'missing raspberry pi detection probe: %s\n' "$probe" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
# The probes must stay registered under the names the gate consumes.
|
||||||
|
for var in grep_cpuinfo_raspberrypi grep_device_tree_model_raspberrypi; do
|
||||||
|
grep -Fq -- "register: $var" "$tasks_file" || {
|
||||||
|
printf 'detection probe is not registered as %s\n' "$var" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
# The gate must keep keying on rc 0 and must tolerate a missing rc so an
|
||||||
|
# undefined result cannot be read as "this host is a Raspberry Pi".
|
||||||
|
grep -Eq -- 'when:.*grep_cpuinfo_raspberrypi\.rc.*== 0.*grep_device_tree_model_raspberrypi\.rc.*== 0' \
|
||||||
|
"$tasks_file" || {
|
||||||
|
printf 'raspberry_pi gate no longer tests both probe return codes for 0\n' >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
grep -Eq -- 'grep_cpuinfo_raspberrypi\.rc \| default\(1\)' "$tasks_file" || {
|
||||||
|
printf 'raspberry_pi gate does not default the /proc/cpuinfo probe rc\n' >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
grep -Eq -- 'grep_device_tree_model_raspberrypi\.rc \| default\(1\)' "$tasks_file" || {
|
||||||
|
printf 'raspberry_pi gate does not default the /proc/device-tree probe rc\n' >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# The distro specific include must remain gated on the detection result so a
|
||||||
|
# non Raspberry Pi host skips setup/ and teardown/ entirely.
|
||||||
|
grep -Eq -- 'raspberry_pi\|default\(false\)' "$tasks_file" || {
|
||||||
|
printf 'OS specific tasks are no longer gated on raspberry_pi\n' >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
printf 'Raspberry Pi detection regression test passed\n'
|
||||||
@@ -68,7 +68,7 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
|
||||||
- name: Ensure SHA pinned actions
|
- name: Ensure SHA pinned actions
|
||||||
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@c5fc58bd0be7a4b94b73ce40250322d5b838a108 # 5.0.7
|
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@60e3a74c7b74a319e8e53e46bc455205f7173e1a # 5.0.8
|
||||||
with:
|
with:
|
||||||
allowlist: |
|
allowlist: |
|
||||||
aws-actions/
|
aws-actions/
|
||||||
|
|||||||
+12
-4
@@ -23,10 +23,6 @@ repos:
|
|||||||
additional_dependencies: [ansible-core==2.18.0]
|
additional_dependencies: [ansible-core==2.18.0]
|
||||||
language_version: python3.12
|
language_version: python3.12
|
||||||
args: [--offline]
|
args: [--offline]
|
||||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
|
||||||
rev: v0.9.0.6
|
|
||||||
hooks:
|
|
||||||
- id: shellcheck
|
|
||||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||||
rev: v1.5.4
|
rev: v1.5.4
|
||||||
hooks:
|
hooks:
|
||||||
@@ -38,6 +34,12 @@ repos:
|
|||||||
- id: fix-smartquotes
|
- id: fix-smartquotes
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
|
- id: shellcheck
|
||||||
|
name: shellcheck
|
||||||
|
entry: shellcheck
|
||||||
|
language: python
|
||||||
|
additional_dependencies: [shellcheck-py==0.11.0.1]
|
||||||
|
types: [shell]
|
||||||
- id: cleanup-runner-resources-test
|
- id: cleanup-runner-resources-test
|
||||||
name: cleanup runner resources test
|
name: cleanup runner resources test
|
||||||
entry: .github/scripts/test-cleanup-runner-resources.sh
|
entry: .github/scripts/test-cleanup-runner-resources.sh
|
||||||
@@ -74,6 +76,12 @@ repos:
|
|||||||
language: system
|
language: system
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
files: ^roles/prereq/(tasks/main|defaults/main)\.yml$|^\.github/scripts/test-disable-swap\.sh$
|
files: ^roles/prereq/(tasks/main|defaults/main)\.yml$|^\.github/scripts/test-disable-swap\.sh$
|
||||||
|
- id: raspberrypi-detection-test
|
||||||
|
name: Raspberry Pi detection test
|
||||||
|
entry: .github/scripts/test-raspberrypi-detection.sh
|
||||||
|
language: system
|
||||||
|
pass_filenames: false
|
||||||
|
files: ^roles/raspberrypi/(tasks/main|defaults/main)\.yml$|^\.github/scripts/test-raspberrypi-detection\.sh$
|
||||||
- id: cilium-bgp-manifest-test
|
- id: cilium-bgp-manifest-test
|
||||||
name: Cilium BGP manifest test
|
name: Cilium BGP manifest test
|
||||||
entry: python3 .github/scripts/test-cilium-bgp-manifest.py
|
entry: python3 .github/scripts/test-cilium-bgp-manifest.py
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
ansible-core>=2.19.12
|
ansible-core>=2.19.13
|
||||||
jmespath>=1.1.0
|
jmespath>=1.1.0
|
||||||
jsonpatch>=1.33
|
jsonpatch>=1.33
|
||||||
kubernetes>=29.0.0
|
kubernetes>=29.0.0
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
#
|
#
|
||||||
ansible-compat==4.1.11
|
ansible-compat==4.1.11
|
||||||
# via molecule
|
# via molecule
|
||||||
ansible-core==2.19.12
|
ansible-core==2.19.13
|
||||||
# via
|
# via
|
||||||
# -r requirements.in
|
# -r requirements.in
|
||||||
# ansible-compat
|
# ansible-compat
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ retry_count: 20
|
|||||||
# yamllint disable rule:line-length
|
# yamllint disable rule:line-length
|
||||||
server_init_args: >-
|
server_init_args: >-
|
||||||
{% if groups[group_name_master | default('master')] | length > 1 %}
|
{% if groups[group_name_master | default('master')] | length > 1 %}
|
||||||
{% if ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] %}
|
{% if ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname'] %}
|
||||||
--cluster-init
|
--cluster-init
|
||||||
{% else %}
|
{% else %}
|
||||||
--server https://{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(",") | first | ansible.utils.ipwrap }}:6443
|
--server https://{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(",") | first | ansible.utils.ipwrap }}:6443
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
no_log: true
|
no_log: true
|
||||||
register: k3s_input_firewall_rules
|
register: k3s_input_firewall_rules
|
||||||
|
|
||||||
- name: Ping the primary Kubernetes API address from {{ ansible_hostname }}
|
- name: Ping the primary Kubernetes API address from {{ ansible_facts.hostname }}
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv:
|
argv:
|
||||||
- ping
|
- ping
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
no_log: true
|
no_log: true
|
||||||
register: k3s_primary_api_ping
|
register: k3s_primary_api_ping
|
||||||
|
|
||||||
- name: Probe primary Kubernetes API from {{ ansible_hostname }}
|
- name: Probe primary Kubernetes API from {{ ansible_facts.hostname }}
|
||||||
ansible.builtin.wait_for:
|
ansible.builtin.wait_for:
|
||||||
host: "{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(',') | first }}"
|
host: "{{ hostvars[groups[group_name_master | default('master')][0]].k3s_node_ip | split(',') | first }}"
|
||||||
port: 6443
|
port: 6443
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
become: false
|
become: false
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: content.j2
|
src: content.j2
|
||||||
dest: "{{ log_destination }}/k3s-init@{{ ansible_hostname }}.log"
|
dest: "{{ log_destination }}/k3s-init@{{ ansible_facts['hostname'] }}.log"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
vars:
|
vars:
|
||||||
content: |
|
content: |
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
become: false
|
become: false
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: content.j2
|
src: content.j2
|
||||||
dest: "{{ log_destination }}/network@{{ ansible_hostname }}.log"
|
dest: "{{ log_destination }}/network@{{ ansible_facts['hostname'] }}.log"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
vars:
|
vars:
|
||||||
content: |
|
content: |
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: >-
|
cmd: >-
|
||||||
{{ k3s_kubectl_binary | default('k3s kubectl') }} get node
|
{{ k3s_kubectl_binary | default('k3s kubectl') }} get node
|
||||||
{{ hostvars[joining_master].ansible_hostname }}
|
{{ hostvars[joining_master].ansible_facts['hostname'] }}
|
||||||
delegate_to: "{{ groups[group_name_master | default('master')][0] }}"
|
delegate_to: "{{ groups[group_name_master | default('master')][0] }}"
|
||||||
register: joined_master
|
register: joined_master
|
||||||
until: joined_master.rc == 0
|
until: joined_master.rc == 0
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Download vip cloud provider manifest to first master
|
- name: Download vip cloud provider manifest to first master
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
@@ -19,7 +20,8 @@
|
|||||||
retries: "{{ download_retries }}"
|
retries: "{{ download_retries }}"
|
||||||
delay: "{{ download_delay }}"
|
delay: "{{ download_delay }}"
|
||||||
until: kube_vip_manifest_download is succeeded
|
until: kube_vip_manifest_download is succeeded
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Copy kubevip configMap manifest to first master
|
- name: Copy kubevip configMap manifest to first master
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -28,4 +30,5 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
expected_control_plane_names: >-
|
expected_control_plane_names: >-
|
||||||
{{
|
{{
|
||||||
groups[group_name_master | default('master')]
|
groups[group_name_master | default('master')]
|
||||||
| map('extract', hostvars, 'ansible_hostname')
|
| map('extract', hostvars, ['ansible_facts', 'hostname'])
|
||||||
| list
|
| list
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -183,24 +183,24 @@
|
|||||||
|
|
||||||
- name: Create directory .kube
|
- name: Create directory .kube
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ ansible_user_dir }}/.kube"
|
path: "{{ ansible_facts['user_dir'] }}/.kube"
|
||||||
state: directory
|
state: directory
|
||||||
owner: "{{ ansible_user_id }}"
|
owner: "{{ ansible_facts['user_id'] }}"
|
||||||
mode: u=rwx,g=rx,o=
|
mode: u=rwx,g=rx,o=
|
||||||
|
|
||||||
- name: Copy config file to user home directory
|
- name: Copy config file to user home directory
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: /etc/rancher/k3s/k3s.yaml
|
src: /etc/rancher/k3s/k3s.yaml
|
||||||
dest: "{{ ansible_user_dir }}/.kube/config"
|
dest: "{{ ansible_facts['user_dir'] }}/.kube/config"
|
||||||
remote_src: true
|
remote_src: true
|
||||||
owner: "{{ ansible_user_id }}"
|
owner: "{{ ansible_facts['user_id'] }}"
|
||||||
mode: u=rw,g=,o=
|
mode: u=rw,g=,o=
|
||||||
|
|
||||||
- name: Configure kubectl cluster to {{ endpoint_url }}
|
- name: Configure kubectl cluster to {{ endpoint_url }}
|
||||||
ansible.builtin.command: >-
|
ansible.builtin.command: >-
|
||||||
{{ k3s_kubectl_binary | default('k3s kubectl') }} config set-cluster default
|
{{ k3s_kubectl_binary | default('k3s kubectl') }} config set-cluster default
|
||||||
--server={{ endpoint_url }}
|
--server={{ endpoint_url }}
|
||||||
--kubeconfig {{ ansible_user_dir }}/.kube/config
|
--kubeconfig {{ ansible_facts['user_dir'] }}/.kube/config
|
||||||
changed_when: true
|
changed_when: true
|
||||||
vars:
|
vars:
|
||||||
endpoint_url: >-
|
endpoint_url: >-
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: "Download to first master: manifest for metallb-{{ metal_lb_type }}"
|
- name: "Download to first master: manifest for metallb-{{ metal_lb_type }}"
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
@@ -19,7 +20,8 @@
|
|||||||
retries: "{{ download_retries }}"
|
retries: "{{ download_retries }}"
|
||||||
delay: "{{ download_delay }}"
|
delay: "{{ download_delay }}"
|
||||||
until: metallb_manifest_download is succeeded
|
until: metallb_manifest_download is succeeded
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Set image versions in manifest for metallb-{{ metal_lb_type }}
|
- name: Set image versions in manifest for metallb-{{ metal_lb_type }}
|
||||||
ansible.builtin.replace:
|
ansible.builtin.replace:
|
||||||
@@ -31,13 +33,15 @@
|
|||||||
to: metallb/speaker:{{ metal_lb_speaker_tag_version }}
|
to: metallb/speaker:{{ metal_lb_speaker_tag_version }}
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.change }} => {{ item.to }}"
|
label: "{{ item.change }} => {{ item.to }}"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Read back MetalLB manifest from first master
|
- name: Read back MetalLB manifest from first master
|
||||||
ansible.builtin.slurp:
|
ansible.builtin.slurp:
|
||||||
src: /var/lib/rancher/k3s/server/manifests/metallb-crds.yaml
|
src: /var/lib/rancher/k3s/server/manifests/metallb-crds.yaml
|
||||||
register: metallb_manifest
|
register: metallb_manifest
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Check the MetalLB speaker image reference is present
|
- name: Check the MetalLB speaker image reference is present
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
@@ -46,7 +50,8 @@
|
|||||||
('quay.io/metallb/speaker:' ~ metal_lb_speaker_tag_version) in
|
('quay.io/metallb/speaker:' ~ metal_lb_speaker_tag_version) in
|
||||||
(metallb_manifest.content | default('') | b64decode)
|
(metallb_manifest.content | default('') | b64decode)
|
||||||
}}
|
}}
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Fail if MetalLB speaker tag was not applied to the manifest
|
- name: Fail if MetalLB speaker tag was not applied to the manifest
|
||||||
ansible.builtin.fail:
|
ansible.builtin.fail:
|
||||||
@@ -56,5 +61,6 @@
|
|||||||
was not found in the downloaded manifest. The upstream image
|
was not found in the downloaded manifest. The upstream image
|
||||||
reference may have changed.
|
reference may have changed.
|
||||||
when:
|
when:
|
||||||
- ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
- >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
- not metallb_manifest_has_speaker_tag
|
- not metallb_manifest_has_speaker_tag
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Copy kube-vip RBAC manifest to first master
|
- name: Copy kube-vip RBAC manifest to first master
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -19,7 +20,8 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
|
|
||||||
- name: Copy vip manifest to first master
|
- name: Copy vip manifest to first master
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -28,4 +30,5 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy Calico to cluster
|
- name: Deploy Calico to cluster
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname']
|
||||||
run_once: true
|
run_once: true
|
||||||
block:
|
block:
|
||||||
- name: Create manifests directory on first master
|
- name: Create manifests directory on first master
|
||||||
|
|||||||
@@ -184,7 +184,7 @@
|
|||||||
--helm-set loadBalancer.mode={{ bpf_lb_mode }}
|
--helm-set loadBalancer.mode={{ bpf_lb_mode }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
environment:
|
environment:
|
||||||
KUBECONFIG: "{{ ansible_user_dir }}/.kube/config"
|
KUBECONFIG: "{{ ansible_facts['user_dir'] }}/.kube/config"
|
||||||
register: cilium_install_result
|
register: cilium_install_result
|
||||||
changed_when: cilium_install_result.rc == 0
|
changed_when: cilium_install_result.rc == 0
|
||||||
# cilium install/upgrade fetches the Helm chart from helm.cilium.io, which is
|
# cilium install/upgrade fetches the Helm chart from helm.cilium.io, which is
|
||||||
@@ -227,7 +227,7 @@
|
|||||||
- name: Wait for Cilium status to be healthy
|
- name: Wait for Cilium status to be healthy
|
||||||
ansible.builtin.command: cilium status --wait
|
ansible.builtin.command: cilium status --wait
|
||||||
environment:
|
environment:
|
||||||
KUBECONFIG: "{{ ansible_user_dir }}/.kube/config"
|
KUBECONFIG: "{{ ansible_facts['user_dir'] }}/.kube/config"
|
||||||
register: cilium_status
|
register: cilium_status
|
||||||
changed_when: false
|
changed_when: false
|
||||||
until: cilium_status.rc == 0
|
until: cilium_status.rc == 0
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /tmp/k3s
|
path: /tmp/k3s
|
||||||
state: directory
|
state: directory
|
||||||
owner: "{{ ansible_user_id }}"
|
owner: "{{ ansible_facts['user_id'] }}"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
with_items: "{{ groups[group_name_master | default('master')] }}"
|
with_items: "{{ groups[group_name_master | default('master')] }}"
|
||||||
run_once: true
|
run_once: true
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: metallb.crs.j2
|
src: metallb.crs.j2
|
||||||
dest: /tmp/k3s/metallb-crs.yaml
|
dest: /tmp/k3s/metallb-crs.yaml
|
||||||
owner: "{{ ansible_user_id }}"
|
owner: "{{ ansible_facts['user_id'] }}"
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
with_items: "{{ groups[group_name_master | default('master')] }}"
|
with_items: "{{ groups[group_name_master | default('master')] }}"
|
||||||
run_once: true
|
run_once: true
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
- name: Set SELinux to disabled state
|
- name: Set SELinux to disabled state
|
||||||
ansible.posix.selinux:
|
ansible.posix.selinux:
|
||||||
state: disabled
|
state: disabled
|
||||||
when: ansible_os_family == "RedHat"
|
when: ansible_facts.os_family == "RedHat"
|
||||||
|
|
||||||
- name: Enable IPv4 forwarding
|
- name: Enable IPv4 forwarding
|
||||||
ansible.posix.sysctl:
|
ansible.posix.sysctl:
|
||||||
@@ -63,31 +63,39 @@
|
|||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
register: br_netfilter_exists
|
register: br_netfilter_exists
|
||||||
changed_when: false
|
changed_when: false
|
||||||
when: ansible_os_family == "RedHat"
|
when: ansible_facts.os_family == "RedHat"
|
||||||
tags: sysctl
|
tags: sysctl
|
||||||
|
|
||||||
- name: Install kernel-modules-extra if br_netfilter missing
|
- name: Install kernel-modules-extra if br_netfilter missing
|
||||||
ansible.builtin.yum:
|
ansible.builtin.yum:
|
||||||
name: kernel-modules-extra
|
name: "kernel-modules-extra-{{ ansible_kernel }}"
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
register: kernel_modules_installed
|
register: kernel_modules_installed
|
||||||
when:
|
when:
|
||||||
- ansible_os_family == "RedHat"
|
- ansible_facts.os_family == "RedHat"
|
||||||
- br_netfilter_exists.stdout | int == 0
|
- br_netfilter_exists.stdout | int == 0
|
||||||
|
|
||||||
|
- name: Reboot node if kernel modules package was installed
|
||||||
|
ansible.builtin.reboot:
|
||||||
|
msg: "Rebooting to apply new kernel modules package"
|
||||||
|
reboot_timeout: 300
|
||||||
|
when:
|
||||||
|
- ansible_facts.os_family == "RedHat"
|
||||||
|
- kernel_modules_installed is changed
|
||||||
|
|
||||||
- name: Add br_netfilter to /etc/modules-load.d/
|
- name: Add br_netfilter to /etc/modules-load.d/
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: br_netfilter
|
content: br_netfilter
|
||||||
dest: /etc/modules-load.d/br_netfilter.conf
|
dest: /etc/modules-load.d/br_netfilter.conf
|
||||||
mode: u=rw,g=,o=
|
mode: u=rw,g=,o=
|
||||||
when: ansible_os_family == "RedHat"
|
when: ansible_facts.os_family == "RedHat"
|
||||||
|
|
||||||
- name: Load br_netfilter
|
- name: Load br_netfilter
|
||||||
community.general.modprobe:
|
community.general.modprobe:
|
||||||
name: br_netfilter
|
name: br_netfilter
|
||||||
state: present
|
state: present
|
||||||
when: ansible_os_family == "RedHat"
|
when: ansible_facts.os_family == "RedHat"
|
||||||
|
|
||||||
- name: Set bridge-nf-call-iptables (just to be sure)
|
- name: Set bridge-nf-call-iptables (just to be sure)
|
||||||
ansible.posix.sysctl:
|
ansible.posix.sysctl:
|
||||||
@@ -95,7 +103,7 @@
|
|||||||
value: "1"
|
value: "1"
|
||||||
state: present
|
state: present
|
||||||
reload: true
|
reload: true
|
||||||
when: ansible_os_family == "RedHat"
|
when: ansible_facts.os_family == "RedHat"
|
||||||
loop:
|
loop:
|
||||||
- net.bridge.bridge-nf-call-iptables
|
- net.bridge.bridge-nf-call-iptables
|
||||||
- net.bridge.bridge-nf-call-ip6tables
|
- net.bridge.bridge-nf-call-ip6tables
|
||||||
@@ -103,10 +111,10 @@
|
|||||||
|
|
||||||
- name: Add /usr/local/bin to sudo secure_path
|
- name: Add /usr/local/bin to sudo secure_path
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
line: Defaults secure_path = {{ secure_path[ansible_os_family] }}
|
line: Defaults secure_path = {{ secure_path[ansible_facts.os_family] }}
|
||||||
regexp: Defaults(\s)*secure_path(\s)*=
|
regexp: Defaults(\s)*secure_path(\s)*=
|
||||||
state: present
|
state: present
|
||||||
insertafter: EOF
|
insertafter: EOF
|
||||||
path: /etc/sudoers
|
path: /etc/sudoers
|
||||||
validate: visudo -cf %s
|
validate: visudo -cf %s
|
||||||
when: ansible_os_family in [ "RedHat", "Suse" ]
|
when: ansible_facts.os_family in [ "RedHat", "Suse" ]
|
||||||
@@ -1,20 +1,27 @@
|
|||||||
---
|
---
|
||||||
|
# The probes below must run in check mode as well. The command module does not
|
||||||
|
# execute under --check, it returns rc 0 with "Command would have run if not in
|
||||||
|
# check mode", which would otherwise mark every host as a Raspberry Pi and make
|
||||||
|
# check runs apply the distro specific tasks. The rc values mean: 0 matched, 1 no
|
||||||
|
# match, 2 the file is absent (no /proc/device-tree on non ARM systems).
|
||||||
- name: Test for raspberry pi /proc/cpuinfo
|
- name: Test for raspberry pi /proc/cpuinfo
|
||||||
ansible.builtin.command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo
|
ansible.builtin.command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo
|
||||||
register: grep_cpuinfo_raspberrypi
|
register: grep_cpuinfo_raspberrypi
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
- name: Test for raspberry pi /proc/device-tree/model
|
- name: Test for raspberry pi /proc/device-tree/model
|
||||||
ansible.builtin.command: grep -E "Raspberry Pi" /proc/device-tree/model
|
ansible.builtin.command: grep -E "Raspberry Pi" /proc/device-tree/model
|
||||||
register: grep_device_tree_model_raspberrypi
|
register: grep_device_tree_model_raspberrypi
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
- name: Set raspberry_pi fact to true
|
- name: Set raspberry_pi fact to true
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
raspberry_pi: true
|
raspberry_pi: true
|
||||||
when: grep_cpuinfo_raspberrypi.rc == 0 or grep_device_tree_model_raspberrypi.rc == 0
|
when: (grep_cpuinfo_raspberrypi.rc | default(1)) == 0 or (grep_device_tree_model_raspberrypi.rc | default(1)) == 0
|
||||||
|
|
||||||
- name: Set detected_distribution to Raspbian (ARM64 on Raspbian, Debian Buster/Bullseye/Bookworm)
|
- name: Set detected_distribution to Raspbian (ARM64 on Raspbian, Debian Buster/Bullseye/Bookworm)
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
@@ -49,8 +56,8 @@
|
|||||||
with_first_found:
|
with_first_found:
|
||||||
- "{{ action_ }}/{{ detected_distribution }}-{{ detected_distribution_major_version }}.yml"
|
- "{{ action_ }}/{{ detected_distribution }}-{{ detected_distribution_major_version }}.yml"
|
||||||
- "{{ action_ }}/{{ detected_distribution }}.yml"
|
- "{{ action_ }}/{{ detected_distribution }}.yml"
|
||||||
- "{{ action_ }}/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
- "{{ action_ }}/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
|
||||||
- "{{ action_ }}/{{ ansible_distribution }}.yml"
|
- "{{ action_ }}/{{ ansible_facts['distribution'] }}.yml"
|
||||||
- "{{ action_ }}/default.yml"
|
- "{{ action_ }}/default.yml"
|
||||||
vars:
|
vars:
|
||||||
action_: >-
|
action_: >-
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
cluster_hostnames: >-
|
cluster_hostnames: >-
|
||||||
{{
|
{{
|
||||||
groups['k3s_cluster']
|
groups['k3s_cluster']
|
||||||
| map('extract', hostvars, 'ansible_hostname')
|
| map('extract', hostvars, ['ansible_facts', 'hostname'])
|
||||||
| list
|
| list
|
||||||
}}
|
}}
|
||||||
run_once: true
|
run_once: true
|
||||||
@@ -77,9 +77,13 @@
|
|||||||
hosts: master
|
hosts: master
|
||||||
environment: "{{ proxy_env | default({}) }}"
|
environment: "{{ proxy_env | default({}) }}"
|
||||||
tasks:
|
tasks:
|
||||||
- name: Copying kubeconfig from {{ hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname'] }}
|
- name: >-
|
||||||
|
Copying kubeconfig from
|
||||||
|
{{ hostvars[groups[group_name_master | default('master')][0]]['ansible_facts']['hostname'] }}
|
||||||
ansible.builtin.fetch:
|
ansible.builtin.fetch:
|
||||||
src: "{{ ansible_user_dir }}/.kube/config"
|
src: "{{ ansible_facts['user_dir'] }}/.kube/config"
|
||||||
dest: ./kubeconfig
|
dest: ./kubeconfig
|
||||||
flat: true
|
flat: true
|
||||||
when: ansible_hostname == hostvars[groups[group_name_master | default('master')][0]]['ansible_hostname']
|
when: >-
|
||||||
|
ansible_facts.hostname == hostvars[groups[group_name_master | default('master')][0]]
|
||||||
|
['ansible_facts']['hostname']
|
||||||
Reference in new issue
Block a user