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.

76 lines
3.5 KiB

  1. ---
  2. # This could be a role or custom module
  3. # Vars:
  4. # issue_cert_alt_name: Requested Subject Alternative Names, in a list.
  5. # issue_cert_common_name: Common Name included in the cert
  6. # issue_cert_copy_ca: Copy issuing CA cert needed
  7. # issue_cert_dir_mode: Mode of the placed cert directory
  8. # issue_cert_file_group: Group of the placed cert file and directory
  9. # issue_cert_file_mode: Mode of the placed cert file
  10. # issue_cert_file_owner: Owner of the placed cert file and directory
  11. # issue_cert_format: Format for returned data. Can be pem, der, or pem_bundle
  12. # issue_cert_headers: Headers passed into the issue request
  13. # issue_cert_hosts: List of hosts to distribute the cert to
  14. # issue_cert_ip_sans: Requested IP Subject Alternative Names, in a list
  15. # issue_cert_mount_path: Mount point in Vault to make the request to
  16. # issue_cert_path: Full path to the cert, include its name
  17. # issue_cert_role: The Vault role to issue the cert with
  18. # issue_cert_url: Url to reach Vault, including protocol and port
  19. - name: issue_cert | Ensure target directory exists
  20. file:
  21. path: "{{ issue_cert_path | dirname }}"
  22. state: directory
  23. group: "{{ issue_cert_file_group | d('root' )}}"
  24. mode: "{{ issue_cert_dir_mode | d('0755') }}"
  25. owner: "{{ issue_cert_file_owner | d('root') }}"
  26. - name: "issue_cert | Generate the cert for {{ issue_cert_role }}"
  27. uri:
  28. url: "{{ issue_cert_url }}/v1/{{ issue_cert_mount_path|d('pki') }}/issue/{{ issue_cert_role }}"
  29. headers: "{{ issue_cert_headers }}"
  30. method: POST
  31. body_format: json
  32. body:
  33. alt_names: "{{ issue_cert_alt_names | d([]) | join(',') }}"
  34. common_name: "{{ issue_cert_common_name | d(issue_cert_path.rsplit('/', 1)[1].rsplit('.', 1)[0]) }}"
  35. format: "{{ issue_cert_format | d('pem') }}"
  36. ip_sans: "{{ issue_cert_ip_sans | default([]) | join(',') }}"
  37. register: issue_cert_result
  38. delegate_to: "{{ issue_cert_hosts|first }}"
  39. run_once: true
  40. - name: "issue_cert | Copy {{ issue_cert_path }} cert to all hosts"
  41. copy:
  42. content: "{{ issue_cert_result['json']['data']['certificate'] }}"
  43. dest: "{{ issue_cert_path }}"
  44. group: "{{ issue_cert_file_group | d('root' )}}"
  45. mode: "{{ issue_cert_file_mode | d('0644') }}"
  46. owner: "{{ issue_cert_file_owner | d('root') }}"
  47. - name: "issue_cert | Copy key for {{ issue_cert_path }} to all hosts"
  48. copy:
  49. content: "{{ issue_cert_result['json']['data']['private_key'] }}"
  50. dest: "{{ issue_cert_path.rsplit('.', 1)|first }}-key.{{ issue_cert_path.rsplit('.', 1)|last }}"
  51. group: "{{ issue_cert_file_group | d('root' )}}"
  52. mode: "{{ issue_cert_file_mode | d('0640') }}"
  53. owner: "{{ issue_cert_file_owner | d('root') }}"
  54. - name: issue_cert | Copy issuing CA cert
  55. copy:
  56. content: "{{ issue_cert_result['json']['data']['issuing_ca'] }}"
  57. dest: "{{ issue_cert_path | dirname }}/ca.pem"
  58. group: "{{ issue_cert_file_group | d('root' )}}"
  59. mode: "{{ issue_cert_file_mode | d('0644') }}"
  60. owner: "{{ issue_cert_file_owner | d('root') }}"
  61. when: issue_cert_copy_ca|default(false)
  62. - name: issue_cert | Copy certificate serial to all hosts
  63. copy:
  64. content: "{{ hostvars[issue_cert_hosts|first]['issue_cert_result']['json']['data']['serial_number'] }}"
  65. dest: "{{ issue_cert_path.rsplit('.', 1)|first }}.serial }}"
  66. group: "{{ issue_cert_file_group | d('root' )}}"
  67. mode: "{{ issue_cert_file_mode | d('0640') }}"
  68. owner: "{{ issue_cert_file_owner | d('root') }}"