Easy CA management
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.

67 lines
1.8 KiB

  1. ---
  2. # This is an example of how to use Ansible with the ca-server shell.
  3. # In this playbook we assume that you are requesting a ssh-host certificate
  4. # to be used by the host `machine.example.com` and that the server hosting
  5. # the ca-server shell is in your inventory under the name `ca_server`.
  6. #
  7. # We are using ed25519 as our preferred algorithm but any other one may be
  8. # just right, be sure to change both the key and certificate destination.
  9. #
  10. - name: Read host public key
  11. slurp:
  12. src: "/etc/ssh/ssh_host_ed25519_key.pub"
  13. register: vm_public_key
  14. - debug:
  15. var: vm_public_key['content']
  16. verbosity: 2
  17. - name: generate host request
  18. set_fact:
  19. ca_request:
  20. type: 'sign_request'
  21. request:
  22. keyType: 'ssh_host'
  23. hostName: 'machine.example.com'
  24. keyData: "{{ vm_public_key['content'] | b64decode | replace('\n', '')}}"
  25. - debug:
  26. var: ca_request | to_json
  27. verbosity: 2
  28. - raw: "{{ ca_request | to_json }}"
  29. delegate_to: ca_server
  30. delegate_facts: True
  31. register: request_result
  32. failed_when: "( request_result.stdout | string | from_json ).failed"
  33. - set_fact:
  34. request_output: "{{ request_result.stdout | string | from_json }}"
  35. - debug:
  36. var: request_output
  37. verbosity: 2
  38. - debug:
  39. msg: "Please manualy confirm sign request with id {{ request_output.requestID }}"
  40. - name: generate get request
  41. set_fact:
  42. ca_request:
  43. type: 'get_certificate'
  44. requestID: '{{ request_output.requestID }}'
  45. - raw: "{{ ca_request | to_json }}"
  46. delegate_to: ca_server
  47. delegate_facts: True
  48. register: request_result
  49. failed_when: "( request_result.stdout | string | from_json ).failed"
  50. - set_fact:
  51. cert_key: "{{ request_result.stdout | string | from_json }}"
  52. - name: write certificate to host
  53. copy:
  54. content: "{{ cert_key.result }}"
  55. dest: "/etc/ssh/ssh_host_ed25519_key-cert.pub"
  56. register: set_pub_key