使用Ansible列出已安装软件包的通用方法 [英] Generic way to list installed packages using Ansible

查看:569
本文介绍了使用Ansible列出已安装软件包的通用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,在当前设置中,我正在将Ansible与CentOs主机配合使用. 任务之一包含以下行:

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

如上所示,该任务仅对支持yum的主机有效,但是如果我想在Ubuntu或其他Linux发行版上运行它,该怎么办?
在网上进行了一些研究之后,我发现有一个名为package的通用软件包管理器.这样,我就可以安装/卸载软件包,而不必担心底层主机,但是不能像上面看到的那样对它们进行类似list的操作. 是否有任何模块或任何方式可以以通用方式实现此目标而无需创建多个when?

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?

推荐答案

一个选项是包括特定于OS的变量.例如:

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'

这篇关于使用Ansible列出已安装软件包的通用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆