openbsd_pkg: Handle another pkg_add gotcha

* Add '-m' to pkg_add incovation to get access to the "packagename-1.0: ok"
  message.
* Watch for that message if we are about to fail because of stderr in
  package_present().
This commit is contained in:
Patrik Lundin 2013-07-10 18:19:01 +02:00
parent 72d73bcc70
commit 8646df0a1f

View file

@ -104,9 +104,9 @@ def get_package_state(name, specific_version):
# Function used to make sure a package is present. # Function used to make sure a package is present.
def package_present(name, installed_state, specific_version, module): def package_present(name, installed_state, specific_version, module):
if module.check_mode: if module.check_mode:
install_cmd = 'pkg_add -In' install_cmd = 'pkg_add -Imn'
else: else:
install_cmd = 'pkg_add -I' install_cmd = 'pkg_add -Im'
if installed_state is False: if installed_state is False:
@ -124,8 +124,19 @@ def package_present(name, installed_state, specific_version, module):
if rc: if rc:
changed=False changed=False
else: else:
# Depend on stderr instead and fake the return code. # Depend on stderr instead.
if stderr: if stderr:
# There is a corner case where having an empty directory in
# installpath prior to the right location will result in a
# "file:/local/package/directory/ is empty" message on stderr
# while still installing the package, so we need to look for
# for a message like "packagename-1.0: ok" just in case.
match = re.search("\W%s-[^:]+: ok\W" % name, stdout)
if match:
# It turns out we were able to install the package.
pass
else:
# We really did fail, fake the return code.
rc = 1 rc = 1
changed=False changed=False