---
- name: 'Create KV v1 secrets engine'
  vault_ci_enable_engine:
    backend_type: kv
    path: '{{ vault_kv1_mount_point }}'
    options:
      version: 1

- name: 'Create KV v2 secrets engine'
  vault_ci_enable_engine:
    backend_type: kv
    path: '{{ vault_kv2_mount_point }}'
    options:
      version: 2

- name: 'Create KV v2 secrets engine to test unauthorized access'
  vault_ci_enable_engine:
    backend_type: kv
    path: '{{ unauthorized_vault_kv2_mount_point }}'
    options:
      version: 2

- name: 'Create KV v2 secrets engine for cas_required=True'
  vault_ci_enable_engine:
    backend_type: kv
    path: '{{ cas_required_vault_kv2_mount_point }}'
    options:
      version: 2

- name: Set cas_required=True
  vault_ci_write:
    path: "{{ cas_required_vault_kv2_mount_point }}/config"
    data:
      cas_required: true

- name: Create a test policy
  vault_ci_policy_put:
    name: test-policy
    policy: "{{ vault_test_policy }}"

- name: Create an alternate policy
  vault_ci_policy_put:
    name: alt-policy
    policy: "{{ vault_alt_policy }}"

- name: Create a token creator policy
  vault_ci_policy_put:
    name: token-creator
    policy: '{{ vault_token_creator_policy }}'

- name: Create an orphan creator policy
  vault_ci_policy_put:
    name: orphan-creator
    policy: '{{ vault_orphan_creator_policy }}'

- name: Create a policy allowing access to invalid kv2 paths
  vault_ci_policy_put:
    name: invalid-kv2
    policy: '{{ vault_invalid_kv2_path_policy }}'

- name: 'Create KV v1 secrets'
  loop: [1, 2, 3]
  vault_ci_kv_put:
    path: "{{ vault_kv1_path }}/secret{{ item }}"
    version: 1
    mount_point: '{{ vault_kv1_mount_point }}'
    secret:
      value: 'foo{{ item }}'

- name: 'Create KV v2 secrets'
  loop: [1, 2, 3, 4, 5]
  vault_ci_kv_put:
    path: "{{ vault_kv2_path }}/secret{{ item }}"
    version: 2
    mount_point: '{{ vault_kv2_mount_point }}'
    secret:
      value: 'foo{{ item }}'

- name: 'Create KV v2 secrets in unauthorized path'
  loop: [1, 2, 3, 4, 5]
  vault_ci_kv_put:
    path: "{{ vault_kv2_path }}/secret{{ item }}"
    version: 2
    mount_point: '{{ unauthorized_vault_kv2_mount_point }}'
    secret:
      value: 'foo{{ item }}'

- name: 'Update KV v2 secret4 with new value to create version'
  vault_ci_kv_put:
    path: "{{ vault_kv2_path }}/secret4"
    version: 2
    mount_point: '{{ vault_kv2_mount_point }}'
    secret:
      value: 'foo5'

- name: 'Create multiple KV v2 secrets under one path'
  vault_ci_kv_put:
    path: "{{ vault_kv2_multi_path }}/secrets"
    version: 2
    mount_point: '{{ vault_kv2_mount_point }}'
    secret:
      value1: foo1
      value2: foo2
      value3: foo3

- name: Remove existing two-versioned secret
  vault_ci_kv2_destroy_all:
    mount_point: '{{ vault_kv2_mount_point }}'
    path: '{{ vault_kv2_versioned_path }}/twover'

- name: Set up a two-versioned secret (v1)
  vault_ci_kv_put:
    version: 2
    mount_point: '{{ vault_kv2_mount_point }}'
    path: '{{ vault_kv2_versioned_path }}/twover'
    secret:
      a: one
      v: 1

- name: Set up a two-versioned secret (v2)
  vault_ci_kv_put:
    version: 2
    mount_point: '{{ vault_kv2_mount_point }}'
    path: '{{ vault_kv2_versioned_path }}/twover'
    secret:
      a: two
      v: 2

- name: 'Write Canary'
  vault_ci_write:
    path: '{{ vault_configure_canary.path }}'
    data:
      value: '{{ vault_configure_canary.value }}'
