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.

74 lines
2.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. 'pki/issue/' + create_role_name: {'policy': 'write'},
  15. 'pki/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 pki mount
  24. uri:
  25. url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}/v1/pki/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. ## Cert based auth method
  38. - include: gen_cert.yml
  39. vars:
  40. gen_cert_copy_ca: true
  41. gen_cert_hosts: "{{ groups[create_role_group] }}"
  42. gen_cert_mount: "auth-pki"
  43. gen_cert_path: "{{ vault_roles_dir }}/{{ create_role_name }}/issuer.pem"
  44. gen_cert_vault_headers: "{{ hostvars[groups.vault|first]['vault_headers'] }}"
  45. gen_cert_vault_role: "dummy"
  46. gen_cert_vault_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  47. when: vault_role_auth_method == "cert" and inventory_hostname in groups[create_role_group]
  48. - name: create_role | Insert the auth-pki CA as the authenticating CA for that role
  49. uri:
  50. url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}/v1/auth/cert/certs/{{ create_role_name }}"
  51. headers: "{{ hostvars[groups.vault|first]['vault_headers'] }}"
  52. method: POST
  53. body_format: json
  54. body:
  55. certificate: "{{ hostvars[groups[create_role_group]|first]['gen_cert_result']['json']['data']['issuing_ca'] }}"
  56. policies: "{{ create_role_name }}"
  57. status_code: 204
  58. when: vault_role_auth_method == "cert" and inventory_hostname == groups[create_role_group]|first
  59. ## Userpass based auth method
  60. - include: gen_userpass.yml
  61. vars:
  62. gen_userpass_group: "{{ create_role_group }}"
  63. gen_userpass_password: "{{ create_role_password|d(''|to_uuid) }}"
  64. gen_userpass_policies: "{{ create_role_name }}"
  65. gen_userpass_role: "{{ create_role_name }}"
  66. gen_userpass_username: "{{ create_role_name }}"
  67. when: vault_role_auth_method == "userpass" and inventory_hostname in groups[create_role_group]