30-quay-pre-tasks.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ---
  2. # Tasks required by 00-initial-config.adoc.
  3. - name: Create a CA on workstation.
  4. hosts: workstation.lab.example.com
  5. become: no
  6. gather_subset: min
  7. tasks:
  8. # TODO: Only if necessary.
  9. - name: Create directories.
  10. ansible.builtin.file:
  11. path: "{{ ansible_facts['user_dir'] }}/ca/lab-ca/newcerts"
  12. state: directory
  13. recurse: yes
  14. mode: 0700
  15. # TODO: Only if necessary.
  16. - name: Create cert index.
  17. ansible.builtin.copy:
  18. dest: "{{ ansible_facts['user_dir'] }}/ca/lab-ca/index.txt"
  19. mode: 0600
  20. content: ""
  21. # TODO: Only if necessary.
  22. - name: Create cert serial tracker.
  23. ansible.builtin.copy:
  24. dest: "{{ ansible_facts['user_dir'] }}/ca/lab-ca/serial"
  25. mode: 0600
  26. content: "0000"
  27. - name: Ensure openssl.cnf is there and correct.
  28. ansible.builtin.copy:
  29. dest: "{{ ansible_facts['user_dir'] }}/ca/openssl.cnf"
  30. mode: 0600
  31. content: |
  32. [ ca ]
  33. default_ca = CA_default
  34. [ CA_default ]
  35. dir = /home/student/ca/lab-ca
  36. serial = $dir/serial
  37. database = $dir/index.txt
  38. new_certs_dir = $dir/newcerts
  39. certificate = /home/student/ca/ca-cert.pem
  40. private_key = /home/student/ca/ca-key.pem
  41. default_days = 365
  42. default_crl_days= 30
  43. default_md = sha256
  44. policy = policy_any
  45. email_in_dn = no
  46. name_opt = ca_default
  47. cert_opt = ca_default
  48. copy_extensions = copy
  49. [ policy_any ]
  50. countryName = supplied
  51. stateOrProvinceName = optional
  52. organizationName = optional
  53. organizationalUnitName = optional
  54. commonName = supplied
  55. emailAddress = optional
  56. - name: Check if CA key exists to save time
  57. ansible.builtin.stat:
  58. path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  59. get_attributes: no
  60. get_checksum: no
  61. get_mime: no
  62. register: cakey_file
  63. - name: Check if CA cert exists to save time
  64. ansible.builtin.stat:
  65. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  66. get_attributes: no
  67. get_checksum: no
  68. get_mime: no
  69. register: cacert_file
  70. - name: Create a new CA private key, if it does not exist yet.
  71. community.crypto.openssl_privatekey:
  72. path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  73. passphrase: verysecret
  74. type: RSA
  75. cipher: auto
  76. size: 8192
  77. mode: 0600
  78. when: cakey_file.stat.exists == false
  79. - name: Generate a CSR for the CA cert.
  80. community.crypto.openssl_csr:
  81. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  82. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  83. privatekey_passphrase: verysecret
  84. basic_constraints: "CA:TRUE"
  85. basic_constraints_critical: yes
  86. subject:
  87. C: US
  88. ST: North Carolina
  89. L: Raleigh
  90. O: Red Hat
  91. OU: RHT
  92. CN: Classroom Root CA
  93. mode: 0600
  94. when: cacert_file.stat.exists == false
  95. - name: Create a self-signed cert for the CA.
  96. community.crypto.x509_certificate:
  97. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  98. csr_path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  99. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  100. privatekey_passphrase: verysecret
  101. provider: selfsigned
  102. selfsigned_not_after: +510w
  103. mode: 0600
  104. when: cacert_file.stat.exists == false
  105. - name: Get rid of the CSR.
  106. ansible.builtin.file:
  107. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  108. state: absent
  109. - name: Copy CA cert to ca-trust dir.
  110. become: yes
  111. ansible.builtin.copy:
  112. src: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  113. dest: "/etc/pki/ca-trust/source/anchors/lab-ca.pem"
  114. mode: 0644
  115. register: copied
  116. - name: Have workstation trust the CA.
  117. become: yes
  118. command: update-ca-trust
  119. when: copied.changed
  120. ...