问题
Right now in my current setup I am using Ansible with CentOs hosts. One of the tasks contains the following line:
command: yum list installed somepackagename
As seen above the task will only work for hosts which support yum
, but what if I want to run it on Ubuntu or some other Linux distribution?
After researching a bit online I found out that there is a generic package manager called package
. With this I install/uninstall packages without worrying about the underlying hosts but not do something like list
them as seen above.
Is there any module or any way I could achieve this in a generic way without creating multiple when
s?
回答1:
An option is to include OS specific variables. For example:
- name: vars
include_vars:
file: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- "default.yml"
paths: '{{ role_path }}/vars'
来源:https://stackoverflow.com/questions/53333097/generic-way-to-list-installed-packages-using-ansible