---
# task vars are not templated when used as vars, so we'll need to set_fact this evaluate the template
# see: https://github.com/ansible/ansible/issues/73268
- name: Persist defaults
  set_fact:
    '{{ item.key }}': "{{ lookup('vars', item.key) }}"
  loop: "{{ lookup('file', role_path ~ '/defaults/main.yml') | from_yaml | dict2items }}"
  loop_control:
    label: '{{ item.key }}'

- name: Configuration tasks
  module_defaults:
    vault_ci_token_create: '{{ vault_plugins_module_defaults_common }}'
  block:
    - name: 'Create a test non-root token'
      vault_ci_token_create:
        policies: test-policy
      register: user_token_cmd

    - name: 'Create a test non-root token with no default policy'
      vault_ci_token_create:
        policies: test-policy
        no_default_policy: true
      register: user_token_no_default_policy_cmd

- import_tasks: token_test_target.yml
  module_defaults:
    assert:
      quiet: true

- import_tasks: token_test_controller.yml
  module_defaults:
    assert:
      quiet: true
