From b12113c18242ba2976f9899aab64f5c5fa06c507 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 4 Mar 2023 10:38:59 +0100 Subject: [PATCH] [PR #6130/c077818c backport][stable-6] Fixes #6112: community.general.gitlab_runner KeyError: 'access_level' (#6142) Fixes #6112: community.general.gitlab_runner KeyError: 'access_level' (#6130) The fix ensures that no 'KeyError' is raised, when 'access_level' is not provided as module parameter or when 'access_level_on_creation' is false. Signed-off-by: Christoph Fiehe Co-authored-by: Christoph Fiehe (cherry picked from commit c077818c5dfd70ccda3b9d09fa5a8c9bf62f2938) Co-authored-by: cfiehe --- .../6112-fix_key_error_in_gitlab_runner_creation_update.yml | 2 ++ plugins/modules/gitlab_runner.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/6112-fix_key_error_in_gitlab_runner_creation_update.yml diff --git a/changelogs/fragments/6112-fix_key_error_in_gitlab_runner_creation_update.yml b/changelogs/fragments/6112-fix_key_error_in_gitlab_runner_creation_update.yml new file mode 100644 index 0000000000..d752aed347 --- /dev/null +++ b/changelogs/fragments/6112-fix_key_error_in_gitlab_runner_creation_update.yml @@ -0,0 +1,2 @@ +bugfixes: + - gitlab_runner - fix ``KeyError`` on runner creation and update (https://github.com/ansible-collections/community.general/issues/6112). diff --git a/plugins/modules/gitlab_runner.py b/plugins/modules/gitlab_runner.py index f0da30e8f2..22d210b6c2 100644 --- a/plugins/modules/gitlab_runner.py +++ b/plugins/modules/gitlab_runner.py @@ -234,9 +234,8 @@ class GitLabRunner(object): 'maximum_timeout': options['maximum_timeout'], 'tag_list': options['tag_list'], } - if arguments['access_level'] is not None: + if options.get('access_level') is not None: arguments['access_level'] = options['access_level'] - # Because we have already call userExists in main() if self.runner_object is None: arguments['description'] = description @@ -251,7 +250,7 @@ class GitLabRunner(object): access_level_on_creation = False if not access_level_on_creation: - del arguments['access_level'] + arguments.pop('access_level', None) runner = self.create_runner(arguments) changed = True