In ansible at work, I have some servers grouped by their project name. Sometimes this will group varying servers together like db servers, http servers, etc..
I know I can update rpm packages using ansible, but using the below playbook, i believe it'll install the package if its not already installed:
If I ran this against a group of 10 servers, they'd all end up with apache installed, instead of just updating the two servers that have it installed currently.
A way around it that i've found is something like:
(since it's using yum update locally w/ the command module instead of just using the ansible yum module)
BUT, i'd like to know if I can do it using the actual yum module (like first example), but only update 'package' if it's already installed. By using the 2nd way, i'm getting 'changed=1' even if it doesn't update anything.
I know I can update rpm packages using ansible, but using the below playbook, i believe it'll install the package if its not already installed:
Code:
- hosts: prod2
- name: Update apache to latest apache
yum:
name: httpd
state: latest
If I ran this against a group of 10 servers, they'd all end up with apache installed, instead of just updating the two servers that have it installed currently.
A way around it that i've found is something like:
Code:
- hosts: prod2
tasks:
- name: Update if installed
command: /usr/bin/yum update -y {{item}}
with_items:
- httpd
(since it's using yum update locally w/ the command module instead of just using the ansible yum module)
BUT, i'd like to know if I can do it using the actual yum module (like first example), but only update 'package' if it's already installed. By using the 2nd way, i'm getting 'changed=1' even if it doesn't update anything.
Last edited: