main.yml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. size: 4096
  30. mode: 0600
  31. when: cakey_file.stat.exists == false
  32. - name: Generate a CSR for the CA cert.
  33. community.crypto.openssl_csr:
  34. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  35. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  36. basic_constraints: "CA:TRUE"
  37. basic_constraints_critical: yes
  38. subject:
  39. C: US
  40. ST: North Carolina
  41. L: Raleigh
  42. O: Red Hat
  43. OU: RHT
  44. CN: Cert Manager Issuer CA
  45. mode: 0600
  46. when: cacert_file.stat.exists == false
  47. - name: Create a self-signed cert for the CA.
  48. community.crypto.x509_certificate:
  49. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  50. csr_path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  51. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  52. provider: selfsigned
  53. selfsigned_not_after: +510w
  54. mode: 0600
  55. when: cacert_file.stat.exists == false
  56. - name: Get rid of the CSR.
  57. ansible.builtin.file:
  58. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  59. state: absent
  60. - name: Copy CA cert to ca-trust dir.
  61. become: yes
  62. ansible.builtin.copy:
  63. src: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  64. dest: "/etc/pki/ca-trust/source/anchors/cert-mgr-ca.pem"
  65. mode: 0644
  66. register: copied
  67. - name: Have workstation trust the CA.
  68. become: yes
  69. command: update-ca-trust
  70. when: copied.changed
  71. ...