Generic way to list installed packages using Ansible

非 Y 不嫁゛ 提交于 2020-08-08 05:46:05

问题


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 whens?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!