main.yml 2.3 KB

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