• Check it out - we have a chatbot! Go ask TuxBot a question in the Ask Tuxbot section!

ansible - updating only installed packages?

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,034
Reaction score
1,969
Credits
2,176
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:

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:


MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Staff online

Members online


Top