main.yml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ---
  2. # Ensures there is a self-signed CA certificate.
  3. # Ensures the workstation trusts the CA certificate.
  4. - name: Ensure that the target directory is there
  5. ansible.builtin.file:
  6. path: "{{ ansible_facts['user_dir'] }}/ca"
  7. state: directory
  8. owner: student
  9. group: student
  10. mode: 0700
  11. - name: Check if CA key exists to save time
  12. ansible.builtin.stat:
  13. path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  14. get_attributes: no
  15. get_checksum: no
  16. get_mime: no
  17. register: cakey_file
  18. - name: Check if CA cert exists to save time
  19. ansible.builtin.stat:
  20. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  21. get_attributes: no
  22. get_checksum: no
  23. get_mime: no
  24. register: cacert_file
  25. - name: Create a new CA private key, if it does not exist yet.
  26. community.crypto.openssl_privatekey:
  27. path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  28. type: RSA
  29. cipher: auto
  30. size: 4096
  31. mode: 0600
  32. when: cakey_file.stat.exists == false
  33. - name: Generate a CSR for the CA cert.
  34. community.crypto.openssl_csr:
  35. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  36. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  37. privatekey_passphrase: verysecret
  38. basic_constraints: "CA:TRUE"
  39. basic_constraints_critical: yes
  40. subject:
  41. C: US
  42. ST: North Carolina
  43. L: Raleigh
  44. O: Red Hat
  45. OU: RHT
  46. CN: Cert Manager Issuer CA
  47. mode: 0600
  48. when: cacert_file.stat.exists == false
  49. - name: Create a self-signed cert for the CA.
  50. community.crypto.x509_certificate:
  51. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  52. csr_path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  53. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  54. privatekey_passphrase: verysecret
  55. provider: selfsigned
  56. selfsigned_not_after: +510w
  57. mode: 0600
  58. when: cacert_file.stat.exists == false
  59. - name: Get rid of the CSR.
  60. ansible.builtin.file:
  61. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  62. state: absent
  63. - name: Copy CA cert to ca-trust dir.
  64. become: yes
  65. ansible.builtin.copy:
  66. src: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  67. dest: "/etc/pki/ca-trust/source/anchors/cert-mgr-ca.pem"
  68. mode: 0644
  69. register: copied
  70. - name: Have workstation trust the CA.
  71. become: yes
  72. command: update-ca-trust
  73. when: copied.changed
  74. ...