mirror of
https://github.com/techno-tim/k3s-ansible.git
synced 2025-12-26 02:32:59 +01:00
Enhance k3s_agent role with idiomatic Ansible practices for better maintainability.
**Added:** - Structured HTTP Proxy Configuration Block - Added a structured block in `http_proxy.yml` for managing HTTP proxy settings, aligning with Ansible's recommended practices. This includes creating directories and deploying configuration files in a clear, modular fashion. - Conditional Execution for Proxy Setup - Implemented conditional execution for the proxy setup in `http_proxy.yml`, utilizing `proxy_env` to adhere to Ansible's best practices for conditional tasks. - Improved PXE-Boot System Check Block - Introduced a more structured approach in `main.yml` for checking PXE-booted systems, enhancing readability and maintainability. **Changed:** - Adopted Ansible Builtin Modules - Transitioned existing tasks to use `ansible.builtin` modules, ensuring compatibility and future-proofing the role. - Refined Task Grouping - Reorganized tasks into logical blocks, improving the overall structure and readability, and showcasing Ansible's capabilities for efficient task management. - Updated K3s Service Configuration - Modified the K3s service configuration task in `main.yml` for a more streamlined approach using Ansible's template module, reflecting community-driven best practices. **Removed:** - Streamlined Task Definitions - Optimized task definitions to reduce redundancy, focusing on clarity and adherence to the evolving Ansible community standards.
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
---
|
---
|
||||||
|
- name: Manage K3s HTTP Proxy Configuration
|
||||||
- name: Create k3s.service.d directory
|
when: proxy_env is defined
|
||||||
file:
|
block:
|
||||||
|
- name: Create k3s.service.d directory
|
||||||
|
ansible.builtin.file:
|
||||||
path: '{{ systemd_dir }}/k3s.service.d'
|
path: '{{ systemd_dir }}/k3s.service.d'
|
||||||
state: directory
|
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
|
state: directory
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: Deploy the K3s http_proxy configuration file
|
||||||
- name: Copy K3s http_proxy conf file
|
ansible.builtin.template:
|
||||||
template:
|
|
||||||
src: "http_proxy.conf.j2"
|
src: "http_proxy.conf.j2"
|
||||||
dest: "{{ systemd_dir }}/k3s.service.d/http_proxy.conf"
|
dest: "{{ systemd_dir }}/k3s.service.d/http_proxy.conf"
|
||||||
owner: root
|
owner: root
|
||||||
|
|||||||
@@ -1,29 +1,32 @@
|
|||||||
---
|
---
|
||||||
- name: Check if system is PXE-booted
|
- name: Check for PXE-booted system
|
||||||
command: cat /proc/cmdline
|
block:
|
||||||
|
- name: Check if system is PXE-booted
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: cat /proc/cmdline
|
||||||
register: boot_cmdline
|
register: boot_cmdline
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
- name: Set fact for PXE-booted system
|
- name: Set fact for PXE-booted system
|
||||||
set_fact:
|
ansible.builtin.set_fact:
|
||||||
is_pxe_booted: "{{ 'root=/dev/nfs' in boot_cmdline.stdout }}"
|
is_pxe_booted: "{{ 'root=/dev/nfs' in boot_cmdline.stdout }}"
|
||||||
when: boot_cmdline is defined
|
when: boot_cmdline.stdout is defined
|
||||||
|
|
||||||
- name: Deploy K3s http_proxy conf
|
- name: Include http_proxy configuration tasks
|
||||||
include_tasks: http_proxy.yml
|
ansible.builtin.include_tasks: http_proxy.yml
|
||||||
when: proxy_env is defined
|
|
||||||
|
|
||||||
- name: Copy K3s service file
|
- name: Configure the k3s service
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "k3s.service.j2"
|
src: "k3s.service.j2"
|
||||||
dest: "{{ systemd_dir }}/k3s-node.service"
|
dest: "{{ systemd_dir }}/k3s-node.service"
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: 0755
|
mode: '0755'
|
||||||
|
|
||||||
- name: Enable and check K3s service
|
- name: Manage k3s service
|
||||||
systemd:
|
ansible.builtin.systemd:
|
||||||
name: k3s-node
|
name: k3s-node
|
||||||
daemon_reload: yes
|
daemon_reload: true
|
||||||
state: restarted
|
state: restarted
|
||||||
enabled: yes
|
enabled: true
|
||||||
|
|||||||
Reference in New Issue
Block a user