From 573a7b97c699c46e8bb37d7b4ea52d711f1b4c07 Mon Sep 17 00:00:00 2001 From: Veikko Virrankoski <71337077+vvirrank@users.noreply.github.com> Date: Sun, 25 Aug 2024 18:01:05 +0300 Subject: [PATCH] Fix gitlab_project container_expiration_policy for project create (#8790) * Fix gitlab_project container_expiration_policy for project create * Check for container_expiration_policy presence before renaming it * Add missing links to changelog fragment * Fix changelog grammar --- ...-gitlab_project-fix-cleanup-policy-on-project-create.yml | 3 +++ plugins/modules/gitlab_project.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/8790-gitlab_project-fix-cleanup-policy-on-project-create.yml diff --git a/changelogs/fragments/8790-gitlab_project-fix-cleanup-policy-on-project-create.yml b/changelogs/fragments/8790-gitlab_project-fix-cleanup-policy-on-project-create.yml new file mode 100644 index 0000000000..ba171a1178 --- /dev/null +++ b/changelogs/fragments/8790-gitlab_project-fix-cleanup-policy-on-project-create.yml @@ -0,0 +1,3 @@ +bugfixes: + - gitlab_project - fix crash caused by old Gitlab projects not having a ``container_expiration_policy`` attribute (https://github.com/ansible-collections/community.general/pull/8790). + - gitlab_project - fix ``container_expiration_policy`` not being applied when creating a new project (https://github.com/ansible-collections/community.general/pull/8790). diff --git a/plugins/modules/gitlab_project.py b/plugins/modules/gitlab_project.py index 7b53f8639c..c5d2278ba0 100644 --- a/plugins/modules/gitlab_project.py +++ b/plugins/modules/gitlab_project.py @@ -521,6 +521,8 @@ class GitLabProject(object): return True arguments['namespace_id'] = namespace.id + if 'container_expiration_policy' in arguments: + arguments['container_expiration_policy_attributes'] = arguments['container_expiration_policy'] try: project = self._gitlab.projects.create(arguments) except (gitlab.exceptions.GitlabCreateError) as e: @@ -548,9 +550,9 @@ class GitLabProject(object): for arg_key, arg_value in arguments.items(): if arguments[arg_key] is not None: - if getattr(project, arg_key) != arguments[arg_key]: + if getattr(project, arg_key, None) != arguments[arg_key]: if arg_key == 'container_expiration_policy': - old_val = getattr(project, arg_key) + old_val = getattr(project, arg_key, {}) final_val = {key: value for key, value in arg_value.items() if value is not None} if final_val.get('older_than') == '0d':