使用 Ansible,如何使用 yum 同时安装多个 RPM?

Using Ansible, How do I install multiple RPMs with yum at the same time?

我想用 yum 同时安装多个 RPM。我有 with_items 数组中的项目列表。有没有办法连接它并一次性安装它?

- name: Install MongoDB RPM
  yum: name={{ list | join(" ") }} state='present'
  with_items:
    - {'name': mongodb-org,         'file': mongodb-org-3.2.6-1.el6.x86_64.rpm}
    - {'name': mongodb-org-mongos,  'file': mongodb-org-mongos-3.2.6-1.el6.x86_64.rpm}
    - {'name': mongodb-org-server,  'file': mongodb-org-server-3.2.6-1.el6.x86_64.rpm}
    - {'name': mongodb-org-shell,   'file': mongodb-org-shell-3.2.6-1.el6.x86_64.rpm}
    - {'name': mongodb-org-tools,   'file': mongodb-org-tools-3.2.6-1.el6.x86_64.rpm}
  sudo: yes

没有必要这样做。 yum 模块针对循环进行了优化,可以一次性安装所有项目。

来自yum module docs

When used with a loop of package names in a playbook, ansible optimizes the call to the yum module. Instead of calling the module with a single package each time through the loop, ansible calls the module once with all of the package names from the loop.

来自loops docs

The yum and apt modules use with_items to execute fewer package manager transactions.