Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd please sign up again. Thanks!

ansible - updating only installed packages?

Discussion in 'Command Line' started by Rob, May 8, 2017.

  1. Rob

    Rob Administrator
    Staff Member

    Joined:
    Oct 27, 2011
    Messages:
    172
    Likes Received:
    469
    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.
     
    #1 Rob, May 8, 2017
    Last edited: May 8, 2017
  2. Rob

    Rob Administrator
    Staff Member

    Joined:
    Oct 27, 2011
    Messages:
    172
    Likes Received:
    469
    Any ideas?
     

Share This Page