From d15053cb305f253be623afd95dda0071d184689f Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 8 Dec 2020 14:54:29 +0100 Subject: [PATCH] cv_version: ensure version param has a minor part --- .../fragments/1087-content_view_version-safenet.yml | 2 ++ plugins/modules/content_view_version.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/1087-content_view_version-safenet.yml diff --git a/changelogs/fragments/1087-content_view_version-safenet.yml b/changelogs/fragments/1087-content_view_version-safenet.yml new file mode 100644 index 0000000000..2620284f2c --- /dev/null +++ b/changelogs/fragments/1087-content_view_version-safenet.yml @@ -0,0 +1,2 @@ +bugfixes: + - content_view_version - make the ``version`` parameter not fail when the version was entered without a minor part (https://github.com/theforeman/foreman-ansible-modules/issues/1087) diff --git a/plugins/modules/content_view_version.py b/plugins/modules/content_view_version.py index 4d79ca2032..f4ddc1a885 100644 --- a/plugins/modules/content_view_version.py +++ b/plugins/modules/content_view_version.py @@ -80,7 +80,7 @@ server_url: "https://foreman.example.com" content_view: "CV 1" organization: "Default Organization" - version: 2.0 + version: "2.0" lifecycle_environments: - Test - Pre Prod @@ -122,7 +122,7 @@ server_url: "https://foreman.example.com" content_view: "Web Servers" organization: "Default Organization" - version: 1.0 + version: "1.0" state: absent # Obtain information about a Content View and its versions @@ -204,6 +204,13 @@ def main(): module.task_timeout = 60 * 60 + if 'version' in module.foreman_params and '.' not in module.foreman_params['version']: + try: + major_version = int(module.foreman_params['version']) + module.foreman_params['version'] = "{0}.0".format(major_version) + except ValueError: + module.fail_json("The 'version' needs to be in the format 'X.Y', not '{0}'".format(module.foreman_params['version'])) + with module.api_connection(): scope = module.scope_for('organization') content_view = module.lookup_entity('content_view')