You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.9 KiB

  1. ---
  2. # The JSON inside JSON here is intentional (Vault API wants it)
  3. - name: create_role | Create a policy for the new role allowing issuing
  4. uri:
  5. url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}/v1/sys/policy/{{ create_role_name }}"
  6. headers: "{{ hostvars[groups.vault|first]['vault_headers'] }}"
  7. method: PUT
  8. body_format: json
  9. body:
  10. rules: >-
  11. {%- if create_role_policy_rules|d("default") == "default" -%}
  12. {{
  13. { 'path': {
  14. create_role_mount_path + '/issue/' + create_role_name: {'policy': 'write'},
  15. create_role_mount_path + '/roles/' + create_role_name: {'policy': 'read'}
  16. }} | to_json + '\n'
  17. }}
  18. {%- else -%}
  19. {{ create_role_policy_rules | to_json + '\n' }}
  20. {%- endif -%}
  21. status_code: 204
  22. when: inventory_hostname == groups[create_role_group]|first
  23. - name: create_role | Create the new role in the {{ create_role_mount_path }} pki mount
  24. uri:
  25. url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}/v1/{{ create_role_mount_path }}/roles/{{ create_role_name }}"
  26. headers: "{{ hostvars[groups.vault|first]['vault_headers'] }}"
  27. method: POST
  28. body_format: json
  29. body: >-
  30. {%- if create_role_options|d("default") == "default" -%}
  31. {'allow_any_name': true}
  32. {%- else -%}
  33. {{ create_role_options }}
  34. {%- endif -%}
  35. status_code: 204
  36. when: inventory_hostname == groups[create_role_group]|first
  37. ## Userpass based auth method
  38. - include: gen_userpass.yml
  39. vars:
  40. gen_userpass_group: "{{ create_role_group }}"
  41. gen_userpass_password: "{{ create_role_password|d(''|to_uuid) }}"
  42. gen_userpass_policies: "{{ create_role_name }}"
  43. gen_userpass_role: "{{ create_role_name }}"
  44. gen_userpass_username: "{{ create_role_name }}"
  45. when: inventory_hostname in groups[create_role_group]