From 24eab14695660ee7922cc6af7db96aa347ab6cbc Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Wed, 29 Jun 2016 23:57:31 +0200 Subject: [PATCH] openbsd_pkg: fix build=true corner case. * Fix bug where we were actually checking for the availability of the requested package name and not 'sqlports' even if that was the goal. * Add check that the sqlports database file exists before using it. * Sprinkle some debug messages for an easier time following the code when developing. --- .../modules/extras/packaging/os/openbsd_pkg.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py b/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py index 354b746309..ff9ef672ca 100644 --- a/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py +++ b/lib/ansible/modules/extras/packaging/os/openbsd_pkg.py @@ -365,9 +365,14 @@ def get_package_source_path(name, pkg_spec, module): return 'databases/sqlports' else: # try for an exact match first - conn = sqlite3.connect('/usr/local/share/sqlports') + sqlports_db_file = '/usr/local/share/sqlports' + if not os.path.isfile(sqlports_db_file): + module.fail_json(msg="sqlports file '%s' is missing" % sqlports_db_file) + + conn = sqlite3.connect(sqlports_db_file) first_part_of_query = 'SELECT fullpkgpath, fullpkgname FROM ports WHERE fullpkgname' query = first_part_of_query + ' = ?' + module.debug("package_package_source_path(): query: %s" % query) cursor = conn.execute(query, (name,)) results = cursor.fetchall() @@ -377,11 +382,14 @@ def get_package_source_path(name, pkg_spec, module): query = first_part_of_query + ' LIKE ?' if pkg_spec['flavor']: looking_for += pkg_spec['flavor_separator'] + pkg_spec['flavor'] + module.debug("package_package_source_path(): flavor query: %s" % query) cursor = conn.execute(query, (looking_for,)) elif pkg_spec['style'] == 'versionless': query += ' AND fullpkgname NOT LIKE ?' + module.debug("package_package_source_path(): versionless query: %s" % query) cursor = conn.execute(query, (looking_for, "%s-%%" % looking_for,)) else: + module.debug("package_package_source_path(): query: %s" % query) cursor = conn.execute(query, (looking_for,)) results = cursor.fetchall() @@ -465,8 +473,9 @@ def main(): # build sqlports if its not installed yet pkg_spec = {} parse_package_name('sqlports', pkg_spec, module) - installed_state = get_package_state(name, pkg_spec, module) + installed_state = get_package_state('sqlports', pkg_spec, module) if not installed_state: + module.debug("main(): installing sqlports") package_present('sqlports', installed_state, pkg_spec, module) if name == '*':