From d9e734d6628502bdead4712d616a1f0efec1f5e6 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 9 Nov 2020 08:42:59 +0100 Subject: [PATCH] Add a warning when ansible_key label is not found on a secret. (#31) (#1249) * add a warning when ansible_label is not found on a secret. addresses #30 * Update changelogs/fragments/31-docker-secret.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein Backported from https://github.com/ansible-collections/community.docker/commit/22ba76b4e9950f22cb423568c4096656633dcf38 --- changelogs/fragments/community.docker-31-docker-secret.yml | 2 ++ plugins/modules/cloud/docker/docker_secret.py | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 changelogs/fragments/community.docker-31-docker-secret.yml diff --git a/changelogs/fragments/community.docker-31-docker-secret.yml b/changelogs/fragments/community.docker-31-docker-secret.yml new file mode 100644 index 0000000000..d4fcca3f93 --- /dev/null +++ b/changelogs/fragments/community.docker-31-docker-secret.yml @@ -0,0 +1,2 @@ +minor_changes: + - "docker_secret - add a warning when the secret does not have an ``ansible_key`` label but the ``force`` parameter is not set (https://github.com/ansible-collections/community.docker/issues/30, https://github.com/ansible-collections/community.docker/pull/31)." diff --git a/plugins/modules/cloud/docker/docker_secret.py b/plugins/modules/cloud/docker/docker_secret.py index 22dad4cd18..b6ce7f2824 100644 --- a/plugins/modules/cloud/docker/docker_secret.py +++ b/plugins/modules/cloud/docker/docker_secret.py @@ -236,6 +236,9 @@ class SecretManager(DockerBaseClass): if attrs.get('Labels', {}).get('ansible_key'): if attrs['Labels']['ansible_key'] != self.data_key: data_changed = True + else: + if not self.force: + self.client.module.warn("'ansible_key' label not found. Secret will not be changed unless the force parameter is set to 'yes'") labels_changed = not compare_generic(self.labels, attrs.get('Labels'), 'allow_more_present', 'dict') if data_changed or labels_changed or self.force: # if something changed or force, delete and re-create the secret