title: Installing multiple packages in Ansible
body: <p>I have this task in Ansible:</p>
  
  <pre><code>- name: Install mongodb
    yum:
      name:
      - "mongodb-org-{{ mongodb_version }}"
      - "mongodb-org-server-{{ mongodb_version }}"
      - "mongodb-org-mongos-{{ mongodb_version }}"
      - "mongodb-org-shell-{{ mongodb_version }}"
      - "mongodb-org-tools-{{ mongodb_version }}"
      state: present
    notify: Restart mongodb
  </code></pre>
  
  <p>Is there a way I can indicate the version without having to use a loop like this? What is a more "elegant" way of writing this?</p>
  
  <pre><code>- name: Install mongodb
    yum:
      name: "{{ item }}-{{ mongodb_version }}"
      state: present
      loop:
      - mongodb-org-server
      - mongodb-org-mongos
      - mongodb-org-shell
      - mongodb-org-tools
    notify: Restart mongodb
  </code></pre>