Update guideline docs for os specific tasks

We're not actually following this. Let's either update
the docs to reflect on how os specific tasks are handled
or update the roles to follow the guidelines.

Change-Id: I9b987efaf597acd34cbcacccd37415dd205a7fba
This commit is contained in:
Albin Vass 2020-05-28 21:48:18 +02:00
parent 7a5c335cc6
commit acf5764472

View File

@ -96,36 +96,31 @@ Here are a few guidelines to help make roles OS-independent when possible:
* Use the **package** module instead of **yum**, **apt** or other * Use the **package** module instead of **yum**, **apt** or other
distribution-specific commands. distribution-specific commands.
* If more than one specific task is needed for a specific OS, these tasks should * If more than one specific task is needed for a specific OS, these tasks should
be stored in a separate YAML file in a `distros` subdirectory and named after be stored in a separate YAML file named after the specific flavor they target.
the specific flavor they target. The following boilerplate code can be used to The following boilerplate code can be used to target specific flavors:
target specific flavors:
.. code-block:: YAML .. code-block:: YAML
tasks: tasks:
- name: Execute distro-specific tasks - name: Execute distro-specific tasks
include_tasks: "{{ lookup('first_found', params) }}" include_tasks: "{{ item }}"
vars: with_first_found:
params: - "{{ ansible_distribution }}.{{ ansible_distribution_major_version }}.{{ ansible_architecture }}.yaml"
files: - "{{ ansible_distribution }}.{{ ansible_distribution_major_version }}.yaml"
- "mytasks-{{ ansible_distribution }}.{{ ansible_distribution_major_version }}.{{ ansible_architecture }}.yaml" - "{{ ansible_distribution }}.yaml"
- "mytasks-{{ ansible_distribution }}.{{ ansible_distribution_major_version }}.yaml" - "{{ ansible_os_family }}.yaml"
- "mytasks-{{ ansible_distribution }}.yaml" - "default.yaml"
- "mytasks-{{ ansible_os_family }}.yaml"
- "mytasks-default.yaml"
paths:
- distros
If run on Fedora 29 x86_64, this playbook will attempt to include the first If run on Fedora 32 x86_64, this playbook will attempt to include the first
playbook found among tasklist found among:
* `distros/mytasks-Fedora.29.x86_64.yaml` * `Fedora.32.x86_64.yaml`
* `distros/mytasks-Fedora.29.yaml` * `Fedora.32.yaml`
* `distros/mytasks-Fedora.yaml` * `Fedora.yaml`
* `distros/mytasks-RedHat.yaml` * `RedHat.yaml`
* `distros/mytasks-default.yaml` * `default.yaml`
The default playbook should return a failure explaining the host's environment is The default tasklist should return a failure explaining the host's environment is
not supported, or a skip if the tasks were optional. not supported, or a skip if the tasks were optional.
Handling privileges on hosts Handling privileges on hosts