main.yml 2.3 KB

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