handle yum and dnf lockfiles - fixes #44120 (#45359)

* handle yum and dnf lockfiles - fixes #44120

Signed-off-by: Adam Miller <admiller@redhat.com>

* fix logic problem to properly check for dnf lockfile glob

Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
Adam Miller 2018-09-19 15:14:25 -05:00 committed by ansibot
commit 5fdf0290d0
3 changed files with 59 additions and 0 deletions

View file

@ -176,6 +176,22 @@ options:
default: "no"
type: bool
version_added: "2.7"
lock_poll:
description:
- Poll interval to wait for the dnf lockfile to be freed.
- "By default this is set to -1, if you set it to a positive integer it will enable to polling"
required: false
default: -1
type: int
version_added: "2.8"
lock_timeout:
description:
- Amount of time to wait for the dnf lockfile to be freed
- This should be set along with C(lock_poll) to enable the lockfile polling.
required: false
default: 10
type: int
version_added: "2.8"
notes:
- When used with a `loop:` each package will be processed individually, it is much more efficient to pass the list directly to the `name` option.
- Group removal doesn't work if the group was installed with Ansible because
@ -285,6 +301,8 @@ class DnfModule(YumDnf):
super(DnfModule, self).__init__(module)
self._ensure_dnf()
self.lockfile = "/var/cache/dnf/*_lock.pid"
self.pkg_mgr_name = "dnf"
def _sanitize_dnf_error_msg(self, spec, error):
"""

View file

@ -183,6 +183,22 @@ options:
default: "no"
type: bool
version_added: "2.7"
lock_poll:
description:
- Poll interval to wait for the yum lockfile to be freed.
- "By default this is set to -1, if you set it to a positive integer it will enable to polling"
required: false
default: -1
type: int
version_added: "2.8"
lock_timeout:
description:
- Amount of time to wait for the yum lockfile to be freed
- This should be set along with C(lock_poll) to enable the lockfile polling.
required: false
default: 10
type: int
version_added: "2.8"
notes:
- When used with a `loop:` each package will be processed individually,
it is much more efficient to pass the list directly to the `name` option.
@ -365,6 +381,9 @@ class YumModule(YumDnf):
# This populates instance vars for all argument spec params
super(YumModule, self).__init__(module)
self.pkg_mgr_name = "yum"
self.lockfile = '/var/run/yum.pid'
def fetch_rpm_from_url(self, spec):
# FIXME: Remove this once this PR is merged:
# https://github.com/ansible/ansible/pull/19172
@ -1434,6 +1453,8 @@ class YumModule(YumDnf):
if not HAS_YUM_PYTHON:
error_msgs.append('The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.')
self.wait_for_lock()
if self.disable_excludes and yum.__version_info__ < (3, 4):
self.module.fail_json(msg="'disable_includes' is available in yum version 3.4 and onwards.")