我最近发现,软件包模块可以将软件包列表直接带到其name
选项。由于所有软件包都通过一次调用yum / apt进行安装,因此大大加快了软件包的安装过程。
征服以下变量:
managed_packages:
- name: bind-utils
os_family: RedHat
state: present
- name: curl
state: present
- name: dnsutils
os_family: Debian
state: present
以及相应的任务:
- name: manage packages
package:
name: "{{item.name}}"
state: "{{item.state}}"
with_items: "{{managed_packages}}"
when: "'os_family' not in item or item.os_family == ansible_os_family"
我正在寻找一种在此任务中利用此功能的方法。 任何人都有一个想法,如何实现呢?
答案 0 :(得分:0)
这可以通过json_query() filter解决。
- name: manage packages
package:
name: "{{ managed_packages | json_query('[?(state==`' + item + '`) && (!os_family || os_family==`' + ansible_os_family + '`)].name') }}"
state: "{{ item }}"
loop:
- present
- absent