Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/systemd_creds_encrypt/tasks/main.yaml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 - name: Test systemd_creds_encrypt
7 when:
8 - ansible_facts.systemd.version is defined
9 - ansible_facts.systemd.version | int >= 250
10 block:
11 - name: Encrypt secret
12 become: true
13 systemd_creds_encrypt:
14 name: db
15 not_after: +48hr
16 secret: access_token
17 register: encrypted_secret
18
19 - name: Assert encrypted secret output is base64 encoded
20 ansible.builtin.assert:
21 that:
22 - (encrypted_secret.value | b64decode) is truthy
23 fail_msg: "Encrypted secret is not base64 encoded"
24 success_msg: "Encrypted secret is base64 encoded"
25
26 - name: Print the encrypted secret
27 ansible.builtin.debug:
28 msg: "{{ encrypted_secret }}"
29
30 - name: Assert that SetCredentialEncrypted message is not in the output
31 ansible.builtin.assert:
32 that:
33 - '"SetCredentialEncrypted" not in encrypted_secret.value'
34 fail_msg: "SetCredentialEncrypted is in the output"
35 success_msg: "SetCredentialEncrypted is not in the output"
36
37 - name: Encrypt secret
38 become: true
39 community.general.systemd_creds_encrypt:
40 name: web
41 not_after: +5y
42 pretty: true
43 secret: token
44 register: pretty_encrypted_secret
45
46 - name: Pretty print the encrypted secret
47 ansible.builtin.debug:
48 msg: "{{ pretty_encrypted_secret }}"
49
50 - name: Assert that SetCredentialEncrypted message is in the output
51 ansible.builtin.assert:
52 that:
53 - '"SetCredentialEncrypted=web: " in pretty_encrypted_secret.value'
54 fail_msg: "SetCredentialEncrypted is not in the output"
55 success_msg: "SetCredentialEncrypted is in the output"