我正在尝试使用 ansible 获取主机的操作系统系列。这是我使用的命令。
ansible my-host -i hosts.ini -m setup | grep ansible_os_family
这是我的主机文件的样子。
[my-host] myhostvm.com ansible_ssh_pass=mypw ansible_ssh_user=root
然而我收到了这条消息:
“ansible_os_family”:“NA”,
我也尝试运行这个。
ansible my-host -i hosts.ini -m setup | grep ansible_distribution
结果如下:
“ansible_distribution”:“NA”, “ansible_distribution_major_version”:“NA”, “ansible_distribution_release”:“NA”, “ansible_distribution_version”:“NA”,
有人能向我解释为什么它没有返回任何操作系统系列吗?
答案1
获取值的 Ansible 代码ansible_os_family
位于lib/ansible/module_utils/facts.py。
如果目标系统的操作系统系列不包含在OS_FAMILY
列表中,则需要修补 Ansible 代码以添加操作系统系列。当前列表包含:
OS_FAMILY = dict(
RedHat = 'RedHat', Fedora = 'RedHat', CentOS = 'RedHat', Scientific = 'RedHat',
SLC = 'RedHat', Ascendos = 'RedHat', CloudLinux = 'RedHat', PSBM = 'RedHat',
OracleLinux = 'RedHat', OVS = 'RedHat', OEL = 'RedHat', Amazon = 'RedHat',
XenServer = 'RedHat', Ubuntu = 'Debian', Debian = 'Debian', Raspbian = 'Debian', Slackware = 'Slackware', SLES = 'Suse',
SLED = 'Suse', openSUSE = 'Suse', SuSE = 'Suse', SLES_SAP = 'Suse', Gentoo = 'Gentoo', Funtoo = 'Gentoo',
Archlinux = 'Archlinux', Manjaro = 'Archlinux', Mandriva = 'Mandrake', Mandrake = 'Mandrake', Altlinux = 'Altlinux',
Solaris = 'Solaris', Nexenta = 'Solaris', OmniOS = 'Solaris', OpenIndiana = 'Solaris',
SmartOS = 'Solaris', AIX = 'AIX', Alpine = 'Alpine', MacOSX = 'Darwin', FreeBSD = 'FreeBSD', HPUX = 'HP-UX', openSUSE_Leap = 'Suse'
Ansible 检查以/etc/$OS-release
确定操作系统。如果目标系统的操作系统系列在OS_FAMILY
列表中,则应检查是否/etc/$OS-release
正确。