While creating a playbook for a vagrant box, I want to skip install steps if the package is already installed. This seems like such a common scenario but is not expliclity mentioned in the conditional docs as far as I can tell.
I am running a playbook multiple times during testing and want to install packages conditionally so I don't have to keep running tasks which I know are working e.g.
- name: Install useful packages
yum: name={{ item }} state=present
with_items:
- "@development-tools"
- git
- curl
- htop
How would I add a conditional here which only installs the above packages if they are not already installed? Is there another state I can use or do I need to manually run something in the shell which checks if they are installed first? e.g. something using yum list installed <packagename>
or yum info <packagename>
. I would rather not have to create a task for each package as this will become unwieldy when there are lots of packages to install
Ansible is idempotent. You can run yum module as many times as you want. If there is nothing to install that task will end with changed=false status and packages will not be re-installed.