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.

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