30-quay-pre-tasks.yml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. - name: Have utility serve time.
  121. hosts: utility.lab.example.com
  122. become: no
  123. gather_subset: min
  124. tasks:
  125. - name: Ensure we have the correct chrony.conf
  126. become: yes
  127. ansible.builtin.copy:
  128. dest: /etc/chrony.conf
  129. mode: 0644
  130. content: |
  131. # Use public servers from the pool.ntp.org project.
  132. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  133. server 172.25.254.254 iburst
  134. # Record the rate at which the system clock gains/losses time.
  135. driftfile /var/lib/chrony/drift
  136. # Allow the system clock to be stepped in the first three updates
  137. # if its offset is larger than 1 second.
  138. makestep 1.0 3
  139. # Enable kernel synchronization of the real-time clock (RTC).
  140. rtcsync
  141. # Enable hardware timestamping on all interfaces that support it.
  142. #hwtimestamp *
  143. # Increase the minimum number of selectable sources required to adjust
  144. # the system clock.
  145. #minsources 2
  146. # Allow NTP client access from local network.
  147. #allow 192.168.0.0/16
  148. allow all
  149. bindcmdaddress 0.0.0.0
  150. cmdallow all
  151. # Serve time even if not synchronized to a time source.
  152. #local stratum 10
  153. # Specify file containing keys for NTP authentication.
  154. keyfile /etc/chrony.keys
  155. # Get TAI-UTC offset and leap seconds from the system tz database.
  156. leapsectz right/UTC
  157. # Specify directory for log files.
  158. logdir /var/log/chrony
  159. # Select which information is logged.
  160. #log measurements statistics tracking
  161. notify:
  162. - restart chronyd
  163. - name: Ensure firewall allows NTP.
  164. become: yes
  165. ansible.posix.firewalld:
  166. immediate: yes
  167. permanent: yes
  168. zone: "{{ item }}"
  169. service: ntp
  170. state: enabled
  171. loop:
  172. - external
  173. - public
  174. - name: Ensure firewall allows cmdport.
  175. become: yes
  176. ansible.posix.firewalld:
  177. immediate: yes
  178. permanent: yes
  179. zone: "{{ item }}"
  180. port: 323/udp
  181. state: enabled
  182. loop:
  183. - external
  184. - public
  185. handlers:
  186. - name: restart chronyd
  187. become: yes
  188. ansible.builtin.service:
  189. name: chronyd
  190. state: restarted
  191. ...