某些插件,例如yum和apt模块可以将列表直接带到其选项中,这比遍历任务更为理想。有关详细信息,请参见每个操作的文档,现在这里是一个示例:
- name: optimal yum
yum:
name: "{{list_of_packages}}"
state: present
- name: non optimal yum, not only slower but might cause issues with interdependencies
yum:
name: "{{item}}"
state: present
loop: "{{list_of_packages}}"
我正在尝试这样做
- name: Install libvirt
yum:
name: '"@Virtualization Hypervisor" "@Virtualization Client"'
但是无法说@Virtualization Hypervisor @Virtualization Client
不可用。删除环绕单引号或所有引号也不起作用。该如何处理?
目前,我正在使用非最佳解决方案,但我想将两个组安装在一个镜头中。
- name: Install libvirt
yum:
name: "{{ item }}"
state: present
loop:
- "@Virtualization Hypervisor"
- "@Virtualization Client"
答案 0 :(得分:3)
在您的示例中,您没有传递“软件包列表”。你是 传递单个字符串:
- name: Install libvirt
yum:
name: '"@Virtualization Hypervisor" "@Virtualization Client"'
列表看起来像这样:
- name: Install libvirt
yum:
name:
- "@Virtualization Hypervisor"
- "@Virtualization Client"
如果您愿意,以下内容是相同的:
- name: Install libvirt
yum:
name: ["@Virtualization Hypervisor", "@Virtualization Client"]