pkg.upgrade with --exclude=kernel*

147 views
Skip to first unread message

Michael Ward

unread,
Jun 24, 2016, 4:25:38 PM6/24/16
to Salt-users
Heya, we're running RHEL/CentOS, so our package manager is yum.  I'd like clients to be able to run "pkg.upgrade" to get up to date, but I want them to exclude packages that match kernel*, e.g. yum -y update --exclude=kernel*.

I know you can set this in /etc/yum.repos.d/ at a repo-level, but I'd rather not limit it to *all* calls for "yum update," I only want this limitation when calling from salt.

Since pkg.upgrade takes kwargs, I tried a few things like:

salt 'box603.example.edu' pkg.upgrade exclude='kernel*'

Doesn't seem to matter, every variation just results in a plain 'yum -y update'.

Is there any way to achieve this with Salt?

Thanks,
Mike

Clint Dilks

unread,
Jun 26, 2016, 7:45:25 PM6/26/16
to salt-...@googlegroups.com
Hi Michael,

Have you thought of just using cmd.run instead ?

eg

salt <host> cmd.run 'yum update -y --exclude=kernel\*'


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Ward

unread,
Jun 27, 2016, 10:21:55 AM6/27/16
to Salt-users
Hey, that's a good idea.  Duh!  Thanks!

Mike

Rémy Dernat

unread,
Jun 27, 2016, 10:42:36 AM6/27/16
to salt-...@googlegroups.com
Hi,

IMO, I would prefer to use a custom module. I think it is not so hard to code... :

cat _modules/customupgrade.py
```
import re

def upgradeexcl(exclude=None):
    '''
    Upgrade a minion and exclude some content

    CLI Example:

    .. code-block:: bash
        
        salt '*' customupgrade.upgradeexcl "kernel vim"
    '''
    if exclude is not None:
        str_exclude=str(exclude)
        update = __salt__['cmd.run']("yum update -y --exclude='"+str_exclude+"'")
    ret = []
    ret.extend([str_exclude,update])
    return ret

```

I did not try it, but that (~nearly) should work.

The main goal here would be then to integrate it smoothly in a state, for example. I think that if you look at pkg.upgrade, you could to something better. With the 're' module you can also add complex regular expression for your custom module :

pattern = re.compile(str_exclude)
search = pattern.search(...)


Regards,

Rémy
Reply all
Reply to author
Forward
0 new messages