【发布时间】:2017-10-05 17:38:11
【问题描述】:
问题:我有很多需要更新包的节点。有些节点安装了这些软件包,有些则没有。 目标是 1.检查是否使用yum模块安装了一个包。 2. 如果安装包并且更新可用,则运行 yum update
我知道这很容易通过命令或 shell 完成,但效率很低。
tasks:
- name: check if packages are installed
yum: list="{{ item }}"
with_items:
- acpid
- c-ares
- automake
register: packages
- debug:
var: packages
将产生 the results
我想要 ansible 做的是仅在 yum: list 看到软件包已安装并且可以从上述结果中升级时更新软件包。
我不确定是否可以使用 yum 模块。
快速简单的方法就是使用命令:
tasks:
- name: check if packages are installed
command: yum update -y {{ item }}
with_items:
- acpid
- c-ares
- automake
因为 yum update package 只会更新已安装的包。
【问题讨论】:
-
为什么不使用快速简便的方法?
标签: python dictionary ansible nested-lists