LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

How do you install several packages, given by variables, in one task?

Give the module's name a list: name: ["{{ mysql_pkg }}", "{{ web_pkg }}"] (or the block form with dashes). One task, one package-manager transaction, and state: latest brings both to the newest version.

- name: Latest version of necessary packages installed
  ansible.builtin.package:
    name:
      - "{{ mysql_pkg }}"   # mariadb-server
      - "{{ web_pkg }}"     # apache2
    state: latest

Package modules accept a list in name and install everything in a single call, which is faster than a loop and resolves the dependencies together.

state: latest versus state: present:

  • present installs the package if it is missing, and leaves an installed version alone.
  • latest also upgrades an installed package whenever a newer version exists.

latest means a run can upgrade software unexpectedly, which is why production playbooks usually use present and run upgrades on purpose.

Go deeper:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026