Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/consul/tasks/consul_token.yml

raw
1 ---
2 # Copyright (c) 2024, Florian Apolloner (@apollo13)
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: Create a policy with rules
7 community.general.consul_policy:
8 name: "{{ item }}"
9 rules: |
10 key "foo" {
11 policy = "read"
12 }
13 loop:
14 - foo-access
15 - foo-access2
16
17 - name: Create token without accessor
18 community.general.consul_token:
19 state: present
20 register: simple_create_result
21
22 - assert:
23 that:
24 - simple_create_result is changed
25 - simple_create_result.token.AccessorID is truthy
26 - simple_create_result.operation == 'create'
27
28 - name: Create token
29 community.general.consul_token:
30 state: present
31 accessor_id: 07a7de84-c9c7-448a-99cc-beaf682efd21
32 service_identities:
33 - service_name: test
34 datacenters: [test1, test2]
35 node_identities:
36 - node_name: test
37 datacenter: test
38 policies:
39 - name: foo-access
40 - name: foo-access2
41 expiration_ttl: 1h
42 register: create_result
43
44 - assert:
45 that:
46 - create_result is changed
47 - create_result.token.AccessorID == "07a7de84-c9c7-448a-99cc-beaf682efd21"
48 - create_result.operation == 'create'
49
50 - name: Update token
51 community.general.consul_token:
52 state: present
53 accessor_id: 07a7de84-c9c7-448a-99cc-beaf682efd21
54 description: Testing
55 policies:
56 - id: "{{ create_result.token.Policies[-1].ID }}"
57 service_identities: []
58 register: result
59
60 - assert:
61 that:
62 - result is changed
63 - result.operation == 'update'
64
65 - name: Update token (noop)
66 community.general.consul_token:
67 state: present
68 accessor_id: 07a7de84-c9c7-448a-99cc-beaf682efd21
69 policies:
70 - name: foo-access2
71 register: result
72
73 - assert:
74 that:
75 - result is not changed
76 - result.operation is not defined
77
78 - name: Remove token
79 community.general.consul_token:
80 state: absent
81 accessor_id: 07a7de84-c9c7-448a-99cc-beaf682efd21
82 register: result
83
84 - assert:
85 that:
86 - result is changed
87 - result.token is falsy
88 - result.operation == 'remove'