Merge "Update guideline docs for os specific tasks"

This commit is contained in:
Zuul 2020-06-17 15:40:44 +00:00 committed by Gerrit Code Review
commit 07e0a5a6c4

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