jm1.common
Ansible Role jm1.common
This role defines additional facts, e.g. to identify distributions.
Details
New
distribution_idfact: A list that uniquely identifies a distribution release. For example:distribution_id: [ 'CentOS', '8' ]forCentOS 8 (Core)distribution_id: [ 'Debian', '10' ]forDebian 10 (Buster)distribution_id: [ 'Debian', '11' ]forDebian 11 (Bullseye)distribution_id: [ 'Debian', 'Unstable' ]forDebian Unstable (Sid)distribution_id: [ 'Red Hat Enterprise Linux', '8' ]forRed Hat Enterprise Linux (RHEL) 8distribution_id: [ 'Ubuntu', '20.04' ]forUbuntu 20.04 LTS (Focal Fossa)
New
distribution_codenamefact: A list that stores the distribution codename. For example:distribution_codename: [ 'Debian', 'Buster' ]forDebian 10 (Buster)distribution_codename: [ 'Ubuntu', 'Focal' ]forUbuntu 20.04 LTS (Focal Fossa)
NOTE: Not all distributions provide distinct codenames for each release. For example,
ansible_facts['distribution_release']is set toCorefor bothCentOS 7andCentOS 8. Hencedistribution_codenameis not suitable to distinguish between releases, butdistribution_idis an unique identifier!NOTE: On Debian Testing, Unstable aka Sid and Experimental, the fact
distribution_iddiffers depending on whetherlsb_releaseis available or not. If packagelsb-releaseis not installed, thendistribution_id|lastis alwaysNAfor all distributions in development. Iflsb_releaseis available, thendistribution_id|lastisTestingfor Debian Testing andUnstablefor Debian Unstable aka Sid and Debian Experimental.Variables are assigned using
set_fact! Mind Ansible's variable precedence: Variables defined withset_factoverride variables from most other places such ashost_varsandgroup_vars.
Tested OS images
- Cloud images and
Docker images of
Debian 10 (Buster)[amd64] - Cloud images and
Docker images of
Debian 11 (Bullseye)[amd64] - Generic cloud image of
CentOS 7 (Core)[amd64] - Generic cloud image of
CentOS 8 (Core)[amd64] - Ubuntu cloud image of
Ubuntu 18.04 LTS (Bionic Beaver)[amd64] - Ubuntu cloud image of
Ubuntu 20.04 LTS (Focal Fossa)[amd64]
Available on Ansible Galaxy as jm1.common.
Frequently Asked Questions
Why is
distribution_iddefined asansible_facts['distribution_major_version']onDebianandCentOSbutansible_facts['distribution_version']onUbuntu?How is
distribution_idbetter thanansible_facts['distribution_major_version']oransible_facts['distribution_version']?The intention of
distribution_idis to provide a variable that changes whenever a new distribution release might bring breaking changes which demand for updates to Ansible roles, their tasks or default variables. OnDebianandCentOS, theansible_facts['distribution_major_version']fact is a proper change identifier. However, Ubuntu might introduce breaking changes biannually in April and October, henceansible_facts['distribution_version']fits better.Role
jm1.commonpicks the variable which qualifies best as a change identifier and then assigns its value todistribution_id.On Debian Testing, Unstable aka Sid and Experimental sometimes the fact
distribution_id|lastisNAand the other time it is e.g.Testing. Why?For Debian branches without a version number, e.g.
VERSION_IDis not set in/etc/os-releaseon Debian Testing, Ansible returns different values foransible_facts['distribution_major_version']depending on whether the commandlsb_releaseis available on the host. If so, thenansible_facts['distribution_major_version']resolves to e.g.unstableon Debian Unstable aka Sid. Elseansible_facts['distribution_major_version']is alwaysNA.
Requirements
None.
Variables
None.
Dependencies
None.
Example Playbook
- hosts: all
tasks:
- import_role:
name: jm1.common
- debug:
var: distribution_id
For instructions on how to run Ansible playbooks have look at Ansible's Getting Started Guide.
Example Role
Facts from role jm1.common might help to develop Ansible roles with OS-specific defaults:
First off, create OS-agnostic dictionaries in defaults/main.yml. Then use distribution_id
as a dict key to assign values for the host OS from dictionaries to default variables.
For example:
defaults/main.yml:
image_uri: |-
{{
{
'CentOS 8': 'https://...',
'Ubuntu 20.04': 'https://...'
}[distribution_id|join(' ')]
}}
License
GNU General Public License v3.0 or later
See LICENSE.md to see the full text.
Author
ansible-galaxy install jm1.common