summaryrefslogtreecommitdiff
path: root/lib/ansible
diff options
context:
space:
mode:
authorAdam Miller <admiller@redhat.com>2018-11-13 14:04:19 -0600
committeransibot <ansibot@users.noreply.github.com>2018-11-13 15:04:19 -0500
commit34fc66185e8f62f784c5d14233d504a00b3e5a05 (patch)
treed078f97dac473c6315d25020acb56532d7f6b815 /lib/ansible
parent50da27654483f1f35f2002172ce549cb0a566ff2 (diff)
downloadansible-34fc66185e8f62f784c5d14233d504a00b3e5a05.tar.gz
make yum update_only option actually work (#47942)
* make yum update_only option actually work Fixes #40615 Signed-off-by: Adam Miller <admiller@redhat.com> * fix changlog fragment for sanity check Signed-off-by: Adam Miller <admiller@redhat.com> * only attempt an update when there are packages to update Signed-off-by: Adam Miller <admiller@redhat.com> * fix logic to properly handle the precedent of operations Signed-off-by: Adam Miller <admiller@redhat.com> * remove q debug statements Signed-off-by: Adam Miller <admiller@redhat.com>
Diffstat (limited to 'lib/ansible')
-rw-r--r--lib/ansible/modules/packaging/os/yum.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py
index 328c98b645..dd127549e0 100644
--- a/lib/ansible/modules/packaging/os/yum.py
+++ b/lib/ansible/modules/packaging/os/yum.py
@@ -1184,7 +1184,9 @@ class YumModule(YumDnf):
self.module.fail_json(msg="Failed to get nevra information from RPM package: %s" % spec)
# local rpm files can't be updated
- if not self.is_installed(repoq, envra):
+ if self.is_installed(repoq, envra):
+ pkgs['update'].append(spec)
+ else:
pkgs['install'].append(spec)
continue
@@ -1199,13 +1201,15 @@ class YumModule(YumDnf):
self.module.fail_json(msg="Failed to get nevra information from RPM package: %s" % spec)
# local rpm files can't be updated
- if not self.is_installed(repoq, envra):
- pkgs['install'].append(package)
+ if self.is_installed(repoq, envra):
+ pkgs['update'].append(spec)
+ else:
+ pkgs['install'].append(spec)
continue
# dep/pkgname - find it
else:
- if self.is_installed(repoq, spec) or self.update_only:
+ if self.is_installed(repoq, spec):
pkgs['update'].append(spec)
else:
pkgs['install'].append(spec)
@@ -1275,7 +1279,10 @@ class YumModule(YumDnf):
else:
to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo'])))
- res['changes'] = dict(installed=pkgs['install'], updated=to_update)
+ if self.update_only:
+ res['changes'] = dict(installed=[], updated=to_update)
+ else:
+ res['changes'] = dict(installed=pkgs['install'], updated=to_update)
if will_update or pkgs['install']:
res['changed'] = True
@@ -1289,7 +1296,18 @@ class YumModule(YumDnf):
if cmd: # update all
rc, out, err = self.module.run_command(cmd)
res['changed'] = True
- elif pkgs['install'] or will_update:
+ elif self.update_only:
+ if pkgs['update']:
+ cmd = self.yum_basecmd + ['update'] + pkgs['update']
+ lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
+ rc, out, err = self.module.run_command(cmd, environ_update=lang_env)
+ out_lower = out.strip().lower()
+ if not out_lower.endswith("no packages marked for update") and \
+ not out_lower.endswith("nothing to do"):
+ res['changed'] = True
+ else:
+ rc, out, err = [0, '', '']
+ elif pkgs['install'] or will_update and not self.update_only:
cmd = self.yum_basecmd + ['install'] + pkgs['install'] + pkgs['update']
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
rc, out, err = self.module.run_command(cmd, environ_update=lang_env)
@@ -1407,13 +1425,7 @@ class YumModule(YumDnf):
self.module.fail_json(msg="Error setting/accessing repos: %s" % to_native(e))
except yum.Errors.YumBaseError as e:
self.module.fail_json(msg="Error accessing repos: %s" % to_native(e))
- if self.state in ('installed', 'present'):
- if self.disable_gpg_check:
- self.yum_basecmd.append('--nogpgcheck')
- res = self.install(pkgs, repoq)
- elif self.state in ('removed', 'absent'):
- res = self.remove(pkgs, repoq)
- elif self.state == 'latest':
+ if self.state == 'latest' or self.update_only:
if self.disable_gpg_check:
self.yum_basecmd.append('--nogpgcheck')
if self.security:
@@ -1421,6 +1433,12 @@ class YumModule(YumDnf):
if self.bugfix:
self.yum_basecmd.append('--bugfix')
res = self.latest(pkgs, repoq)
+ elif self.state in ('installed', 'present'):
+ if self.disable_gpg_check:
+ self.yum_basecmd.append('--nogpgcheck')
+ res = self.install(pkgs, repoq)
+ elif self.state in ('removed', 'absent'):
+ res = self.remove(pkgs, repoq)
else:
# should be caught by AnsibleModule argument_spec
self.module.fail_json(