summaryrefslogtreecommitdiff
path: root/test/integration/roles/test_consul_kv/tasks/main.yml
blob: 585f93b3719ddf14134b07535f3c99f011e2cf98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
- name: add rules to an acl token
  consul_acl:
    mgmt_token: '{{mgmt_token}}'
    host: '{{acl_host}}'
    name: 'ACL rule for testing'
    rules:
      - key: 'somekey'
        policy: write
  register: test_acl

- name: cleanup from previous failed runs
  consul_kv: key={{item}} state=absent token='{{test_acl.token}}'
  with_items:
    - somekey

- name: add a kv pair to the kv store
  consul_kv: key=somekey value=somevalue token='{{test_acl.token}}'
  register: new_key

- name: verify new key
  assert:
    that:
      - new_key.key == 'somekey'
      - new_key.data.Value == 'somevalue'
      - new_key.changed == true

- name: add an existing kv to the kv store
  consul_kv: key=somekey value=somevalue token='{{test_acl.token}}'
  register: existing_key

- name: verify existing key cause no change
  assert:
    that:
      - existing_key.key == 'somekey'
      - existing_key.data.Value == 'somevalue'
      - existing_key.changed == False

- name: remove an existing kv from the kv store
  consul_kv: key=somekey state=absent token='{{test_acl.token}}'
  register: remove_key

- name: verify removal causes change and existing value is returned
  assert:
    that:
      - remove_key.key == 'somekey'
      - remove_key.data.Value == 'somevalue'
      - remove_key.changed == True

- name: attempting to remove an non-existant kv from the kv store causes no change
  consul_kv: key=not_present state=absent token='{{test_acl.token}}'
  register: non_existant_key

- name: verify removal causes change and existing value is returned
  assert:
    that:
      - non_existant_key.key == 'not_present'
      - non_existant_key.data == None
      - non_existant_key.changed == False

- name: Add a key to lookup with the lookup capability
  consul_kv: key='key/to/lookup_{{item}}' value='somevalue_{{item}}' token='{{test_acl.token}}'
  with_items:
    - one
    - two
  register: lookup_keys

  # necessary to make the new token available to the
- set_fact: acl_token={{test_acl.token}}

- name: kv test
  assert:
    that:
      - "{{item | match('somevalue_one')}}"
  with_consul_kv:
    - 'key/to/lookup_one token={{acl_token}}'


- name: recursive kv lookup test
  assert:
    that:
      - "{{item| match('somevalue_(one|two)')}}"
  with_consul_kv:
    - 'key/to recurse=true token={{acl_token}}'

- name: remove test acl rule
  consul_acl:
    mgmt_token: '{{mgmt_token}}'
    host: '{{acl_host}}'
    token: '{{test_acl.token}}'
    state: absent