Problem: I have many nodes that need package updates. Some of the nodes have these packages installed and some do not. The goal is to 1. check if a package is installed us
The ansible.builtin.yum:
module already updates only if a package is installed. You can loop over a list of items using the loop:
directive, or if it's a short list, declare the variable within the task block and use the yum module's ability to operate over a list. Like the quick and dirty version.
- name: update a list of packages
yum:
name: "{{ packagelist }}"
state: latest
vars:
packagelist:
- acpid
- c-ares
- automake
Or, even simpler:
- name: update a list of packages
yum:
name:
- acpid
- c-ares
- automake
state: latest
Many more examples are available and all the parameters are defined here: Ansible Docs article about yum