OS specific tasks / checks #1

Open
opened 2026-07-09 16:40:57 +02:00 by alessandrovitali · 1 comment
Owner

Strategy for handling multi-OS environments:

  1. Use generic package module with list of variables for different package names etc.

  2. Assert supported OS (fast fail) at start of role / playbook

- name: Ensure target OS is Debian-based
  ansible.builtin.assert:
    that:
      - ansible_facts['os_family'] == "Debian"
    fail_msg: "This role only supports Debian-based operating systems."
    success_msg: "OS verified as Debian-based."

Either add this task to the entrypoint playbook as a pre-task:

---
- name: Configure Homelab Servers
  hosts: all
  
  pre_tasks:
    - name: Ensure target OS is Debian-based
      ansible.builtin.assert:
        that:
          - ansible_facts['os_family'] == "Debian"
        fail_msg: "This playbook and its roles only support Debian-based operating systems."
        success_msg: "OS verified as Debian-based."

  roles:
    - studio.ansible.base
    - studio.ansible.docker
    - studio.ansible.backup

Make all roles dependent on base role with

---
dependencies:
  - role: base

Or create a dedicated validation role like roles/validate_os which needs to run first in every playbook (either add to the README, or include it as a dependency in all roles)

Strategy for handling multi-OS environments: 1. Use generic `package` module with list of variables for different package names etc. 2. Assert supported OS (fast fail) at start of role / playbook ``` - name: Ensure target OS is Debian-based ansible.builtin.assert: that: - ansible_facts['os_family'] == "Debian" fail_msg: "This role only supports Debian-based operating systems." success_msg: "OS verified as Debian-based." ``` Either add this task to the entrypoint playbook as a pre-task: ```yml --- - name: Configure Homelab Servers hosts: all pre_tasks: - name: Ensure target OS is Debian-based ansible.builtin.assert: that: - ansible_facts['os_family'] == "Debian" fail_msg: "This playbook and its roles only support Debian-based operating systems." success_msg: "OS verified as Debian-based." roles: - studio.ansible.base - studio.ansible.docker - studio.ansible.backup ``` Make all roles dependent on `base` role with ```yml --- dependencies: - role: base ``` Or create a dedicated validation role like `roles/validate_os` which _needs_ to run first in every playbook (either add to the README, or include it as a dependency in all roles)
Author
Owner

see #3

see #3
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: studio/ansible#1