Debian Codegraph @

ansible_collections/google/cloud/tests/integration/targets/gcp_secret_manager/tasks/secretslookup.yml

raw symbols SCIP
1 # Copyright 2024 Google Inc.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 ---
15 # Pre-test setup
16 - name: Delete the test secret if it exists
17 google.cloud.gcp_secret_manager:
18 name: "{{ lookup_resource_name }}"
19 version: "all"
20 project: "{{ gcp_project }}"
21 auth_kind: "{{ gcp_cred_kind }}"
22 service_account_file: "{{ gcp_cred_file | default(omit) }}"
23 state: absent
24 - name: Create a secret
25 google.cloud.gcp_secret_manager:
26 name: "{{ lookup_resource_name }}"
27 value: "ansible lookup test secret value"
28 labels:
29 key1: "val1"
30 key2: "val2"
31 project: "{{ gcp_project }}"
32 auth_kind: "{{ gcp_cred_kind }}"
33 service_account_file: "{{ gcp_cred_file | default(omit) }}"
34 state: present
35 - name: Add a new version to a secret
36 google.cloud.gcp_secret_manager:
37 name: "{{ lookup_resource_name }}"
38 value: "ansible lookup test secret value updated"
39 project: "{{ gcp_project }}"
40 auth_kind: "{{ gcp_cred_kind }}"
41 service_account_file: "{{ gcp_cred_file | default(omit) }}"
42 state: present
43 # ----------------------------------------------------------
44 - name: Retrieve the latest secret version of a secret
45 ansible.builtin.set_fact:
46 secret_value: "{{ lookup('google.cloud.gcp_secret_manager', key=lookup_resource_name, project=gcp_project, auth_kind=gcp_cred_kind, service_account_file=gcp_cred_file) | string }}"
47 - name: Assert secret value
48 ansible.builtin.assert:
49 that:
50 - secret_value is contains("ansible lookup test secret value updated")
51 # ----------------------------------------------------------
52 - name: Retrieve the specified secret version of a secret
53 ansible.builtin.set_fact:
54 secret_value: "{{ lookup('google.cloud.gcp_secret_manager', key=lookup_resource_name, version='1', project=gcp_project, auth_kind=gcp_cred_kind, service_account_file=gcp_cred_file) | string }}"
55 - name: Assert secret value
56 ansible.builtin.assert:
57 that:
58 - secret_value is contains("ansible lookup test secret value")
59 # ---------------------------------------------------------
60 # Post-test teardown
61 # If errors happen, don't crash the playbook!
62 - name: Delete the test secret
63 google.cloud.gcp_secret_manager:
64 name: "{{ lookup_resource_name }}"
65 version: "all"
66 project: "{{ gcp_project }}"
67 auth_kind: "{{ gcp_cred_kind }}"
68 service_account_file: "{{ gcp_cred_file | default(omit) }}"
69 state: absent
70 ignore_errors: true