From 5c5cd2dc4d0a58a12233397d9682233f7b4c5e9a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 3 Jan 2019 12:34:46 +0100 Subject: [PATCH] openssl_*: prevent error when path includes no path (#50322) * Prevent error when path includes no path. * Add changelog. --- changelogs/fragments/50322-openssl-path-error.yml | 2 ++ lib/ansible/modules/crypto/openssl_certificate.py | 2 +- lib/ansible/modules/crypto/openssl_csr.py | 2 +- lib/ansible/modules/crypto/openssl_dhparam.py | 2 +- lib/ansible/modules/crypto/openssl_pkcs12.py | 2 +- lib/ansible/modules/crypto/openssl_privatekey.py | 2 +- lib/ansible/modules/crypto/openssl_publickey.py | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/50322-openssl-path-error.yml diff --git a/changelogs/fragments/50322-openssl-path-error.yml b/changelogs/fragments/50322-openssl-path-error.yml new file mode 100644 index 00000000000..4debcb61000 --- /dev/null +++ b/changelogs/fragments/50322-openssl-path-error.yml @@ -0,0 +1,2 @@ +bugfixes: +- "openssl_* - fix error when ``path`` contains a file name without path." diff --git a/lib/ansible/modules/crypto/openssl_certificate.py b/lib/ansible/modules/crypto/openssl_certificate.py index 89fdc203586..96c5bab43d0 100644 --- a/lib/ansible/modules/crypto/openssl_certificate.py +++ b/lib/ansible/modules/crypto/openssl_certificate.py @@ -1041,7 +1041,7 @@ def main(): if module.params['provider'] != 'assertonly' and module.params['csr_path'] is None: module.fail_json(msg='csr_path is required when provider is not assertonly') - base_dir = os.path.dirname(module.params['path']) + base_dir = os.path.dirname(module.params['path']) or '.' if not os.path.isdir(base_dir): module.fail_json( name=base_dir, diff --git a/lib/ansible/modules/crypto/openssl_csr.py b/lib/ansible/modules/crypto/openssl_csr.py index 23bdbe340f8..d9eea9194cd 100644 --- a/lib/ansible/modules/crypto/openssl_csr.py +++ b/lib/ansible/modules/crypto/openssl_csr.py @@ -563,7 +563,7 @@ def main(): except AttributeError: module.fail_json(msg='You need to have PyOpenSSL>=0.15 to generate CSRs') - base_dir = os.path.dirname(module.params['path']) + base_dir = os.path.dirname(module.params['path']) or '.' if not os.path.isdir(base_dir): module.fail_json(name=base_dir, msg='The directory %s does not exist or the file is not a directory' % base_dir) diff --git a/lib/ansible/modules/crypto/openssl_dhparam.py b/lib/ansible/modules/crypto/openssl_dhparam.py index cdcb5f789e6..91304e4d3c9 100644 --- a/lib/ansible/modules/crypto/openssl_dhparam.py +++ b/lib/ansible/modules/crypto/openssl_dhparam.py @@ -191,7 +191,7 @@ def main(): add_file_common_args=True, ) - base_dir = os.path.dirname(module.params['path']) + base_dir = os.path.dirname(module.params['path']) or '.' if not os.path.isdir(base_dir): module.fail_json( name=base_dir, diff --git a/lib/ansible/modules/crypto/openssl_pkcs12.py b/lib/ansible/modules/crypto/openssl_pkcs12.py index 15bbde0b31e..9122766fe10 100644 --- a/lib/ansible/modules/crypto/openssl_pkcs12.py +++ b/lib/ansible/modules/crypto/openssl_pkcs12.py @@ -312,7 +312,7 @@ def main(): if not pyopenssl_found: module.fail_json(msg='The python pyOpenSSL library is required') - base_dir = os.path.dirname(module.params['path']) + base_dir = os.path.dirname(module.params['path']) or '.' if not os.path.isdir(base_dir): module.fail_json( name=base_dir, diff --git a/lib/ansible/modules/crypto/openssl_privatekey.py b/lib/ansible/modules/crypto/openssl_privatekey.py index ae2c30ad14d..6df58c0020b 100644 --- a/lib/ansible/modules/crypto/openssl_privatekey.py +++ b/lib/ansible/modules/crypto/openssl_privatekey.py @@ -582,7 +582,7 @@ def main(): ], ) - base_dir = os.path.dirname(module.params['path']) + base_dir = os.path.dirname(module.params['path']) or '.' if not os.path.isdir(base_dir): module.fail_json( name=base_dir, diff --git a/lib/ansible/modules/crypto/openssl_publickey.py b/lib/ansible/modules/crypto/openssl_publickey.py index 0f7d6af0442..8765daaba2f 100644 --- a/lib/ansible/modules/crypto/openssl_publickey.py +++ b/lib/ansible/modules/crypto/openssl_publickey.py @@ -269,7 +269,7 @@ def main(): if not pyopenssl_found: module.fail_json(msg='the python pyOpenSSL module is required') - base_dir = os.path.dirname(module.params['path']) + base_dir = os.path.dirname(module.params['path']) or '.' if not os.path.isdir(base_dir): module.fail_json( name=base_dir,