我如何使用ansible来检测Linux的特定风格,例如“Lubuntu”——Ubuntu的一个变体?
在 Lubuntu 22.04 上,我尝试ansible_distribution
使用以下剧本进行跟踪:
---
- hosts: all
gather_facts: yes
become: false
tasks:
- name: Distribution
debug: msg="{{ ansible_distribution }}"
- name: Distribution version
debug: msg="{{ ansible_distribution_version}}"
- name: Distribution major version
debug: msg="{{ ansible_distribution_major_version }}"
但我得到的Ubuntu
是ansible_distribution
,这不够具体(对于我的任务):
TASK [Distribution] ************************************************************
ok: [127.0.0.1] => {
"msg": "Ubuntu"
}
...
一般来说,如何获得特定 Linux 风格(例如 Lubuntu)的名称?
- 附加信息 -
在 Lubuntu 上,我有:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
答案1
没有识别标准Ubuntu 风格。您可以搜索一下配置。看是否可以知道我正在使用终端运行哪种公认的风味?。例如,
shell> cat /var/log/installer/media-info
Xubuntu 20.04 LTS "Focal Fossa" - Release amd64 (20200423)
安塞布尔没有收集事实关于 Ubuntu 风格。你必须自己去发现。例如,
- hosts: localhost
vars:
my_flavor: "{{ media_info.stdout.split()|first }}"
tasks:
- command: cat /var/log/installer/media-info
register: media_info
- debug:
var: my_flavor
给出
my_flavor: Xubuntu
答案2
您可以使用ansible_distribution_release
您可以通过运行以下命令轻松查看主机上的可用事实:
ansible all -m setup -a "filter=ansible_distribution*"
"ansible_facts": {
"ansible_distribution": "Ubuntu",
"ansible_distribution_file_parsed": true,
"ansible_distribution_file_path": "/etc/os-release",
"ansible_distribution_file_variety": "Debian",
"ansible_distribution_major_version": "22",
"ansible_distribution_release": "jammy",
"ansible_distribution_version": "22.04",
"discovered_interpreter_python": "/usr/bin/python3"
},