Use /etc/os-release to ID Ubuntu/Debian

Ansible facts aren't always enough to determine if a distro is derived
from Ubuntu or not, this is available from `/etc/os-release` when it
contains `ID_LIKE="ubuntu debian"`. This patch uses `/etc/os-release` to
correctly handle Ubuntu installations, e.g. PPA's, for all Ubuntu
derived dirtros rather than just Ubuntu itself.
This commit is contained in:
Kenneth Benzie 2023-08-01 19:14:32 +01:00
parent 58cd98c817
commit df00529f86
5 changed files with 21 additions and 9 deletions

View File

@ -1,5 +1,17 @@
--- ---
- name: slurp /etc/os-release
slurp:
src: /etc/os-release
register: os_release_slurp
- set_fact:
os_release: "{{ os_release_slurp.content |
b64decode | trim() | replace('=', ': ') | from_yaml }}"
- include_tasks: Ubuntu.yaml
when: "'ID_LIKE' in os_release and os_release.ID_LIKE == 'ubuntu debian'"
- name: install apt packages - name: install apt packages
when: "'ID_LIKE' not in os_release"
become: true become: true
apt: apt:
name: name:

View File

@ -1,2 +0,0 @@
---
- include_tasks: Ubuntu.yaml

View File

@ -1,2 +0,0 @@
---
- include_tasks: Ubuntu.yaml

View File

@ -1,5 +1,2 @@
--- ---
- include_tasks: '{{ansible_os_family}}.yaml' - include_tasks: '{{ansible_os_family}}.yaml'
when: ansible_os_family in ['Darwin', 'Windows']
- include_tasks: '{{ansible_distribution}}.yaml'
when: ansible_os_family not in ['Darwin', 'Windows']

View File

@ -1,7 +1,14 @@
--- ---
- name: slurp /etc/os-release
slurp:
src: /etc/os-release
register: os_release_slurp
- set_fact:
os_release: "{{ os_release_slurp.content |
b64decode | trim() | replace('=', ': ') | from_yaml }}"
- name: add neovim stable ppa - name: add neovim stable ppa
when: ansible_distribution == 'Ubuntu' and when: "'ID_LIKE' in os_release and os_release.ID_LIKE == 'ubuntu debian'"
ansible_distribution_version == '20.04'
become: true become: true
apt_repository: apt_repository:
repo: ppa:neovim-ppa/stable repo: ppa:neovim-ppa/stable