30-quay-pre-tasks.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. - name: Create directories.
  9. ansible.builtin.file:
  10. path: "{{ ansible_facts['user_dir'] }}/ca/lab-ca/newcerts"
  11. state: directory
  12. recurse: yes
  13. mode: 0700
  14. - name: Create cert index.
  15. ansible.builtin.copy:
  16. dest: "{{ ansible_facts['user_dir'] }}/ca/lab-ca/index.txt"
  17. mode: 0600
  18. content: ""
  19. - name: Create cert serial tracker.
  20. ansible.builtin.copy:
  21. dest: "{{ ansible_facts['user_dir'] }}/ca/lab-ca/serial"
  22. mode: 0600
  23. content: "0000"
  24. - name: Ensure openssl.cnf is there and correct.
  25. ansible.builtin.copy:
  26. dest: "{{ ansible_facts['user_dir'] }}/ca/openssl.cnf"
  27. mode: 0600
  28. content: |
  29. [ ca ]
  30. default_ca = CA_default
  31. [ CA_default ]
  32. dir = /home/student/ca/lab-ca
  33. serial = $dir/serial
  34. database = $dir/index.txt
  35. new_certs_dir = $dir/newcerts
  36. certificate = /home/student/ca/ca-cert.pem
  37. private_key = /home/student/ca/ca-key.pem
  38. default_days = 365
  39. default_crl_days= 30
  40. default_md = sha256
  41. policy = policy_any
  42. email_in_dn = no
  43. name_opt = ca_default
  44. cert_opt = ca_default
  45. copy_extensions = copy
  46. [ policy_any ]
  47. countryName = supplied
  48. stateOrProvinceName = optional
  49. organizationName = optional
  50. organizationalUnitName = optional
  51. commonName = supplied
  52. emailAddress = optional
  53. - name: Check if CA key exists to save time
  54. ansible.builtin.stat:
  55. path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  56. get_attributes: no
  57. get_checksum: no
  58. get_mime: no
  59. register: cakey_file
  60. - name: Check if CA cert exists to save time
  61. ansible.builtin.stat:
  62. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  63. get_attributes: no
  64. get_checksum: no
  65. get_mime: no
  66. register: cacert_file
  67. - name: Create a new CA private key, if it does not exist yet.
  68. community.crypto.openssl_privatekey:
  69. path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  70. passphrase: verysecret
  71. type: RSA
  72. cipher: auto
  73. size: 8192
  74. mode: 0600
  75. when: cakey_file.stat.exists == false
  76. - name: Generate a CSR for the CA cert.
  77. community.crypto.openssl_csr:
  78. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  79. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  80. privatekey_passphrase: verysecret
  81. basic_constraints: "CA:TRUE"
  82. basic_constraints_critical: yes
  83. subject:
  84. C: US
  85. ST: North Carolina
  86. L: Raleigh
  87. O: Red Hat
  88. OU: RHT
  89. CN: Classroom Root CA
  90. mode: 0600
  91. when: cacert_file.stat.exists == false
  92. - name: Create a self-signed cert for the CA.
  93. community.crypto.x509_certificate:
  94. path: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  95. csr_path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  96. privatekey_path: "{{ ansible_facts['user_dir'] }}/ca/ca-key.pem"
  97. privatekey_passphrase: verysecret
  98. provider: selfsigned
  99. selfsigned_not_after: +510w
  100. mode: 0600
  101. when: cacert_file.stat.exists == false
  102. - name: Get rid of the CSR.
  103. ansible.builtin.file:
  104. path: "{{ ansible_facts['user_dir'] }}/ca/ca-csr.pem"
  105. state: absent
  106. - name: Copy CA cert to ca-trust dir.
  107. become: yes
  108. ansible.builtin.copy:
  109. src: "{{ ansible_facts['user_dir'] }}/ca/ca-cert.pem"
  110. dest: "/etc/pki/ca-trust/source/anchors/lab-ca.pem"
  111. mode: 0644
  112. register: copied
  113. - name: Have workstation trust the CA.
  114. become: yes
  115. command: update-ca-trust
  116. when: copied.changed
  117. - name: Have utility serve time.
  118. hosts: utility.lab.example.com
  119. become: no
  120. gather_subset: min
  121. tasks:
  122. - name: Ensure we have the correct chrony.conf
  123. become: yes
  124. ansible.builtin.copy:
  125. dest: /etc/chrony.conf
  126. mode: 0644
  127. content: |
  128. # Use public servers from the pool.ntp.org project.
  129. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  130. server 172.25.254.254 iburst
  131. # Record the rate at which the system clock gains/losses time.
  132. driftfile /var/lib/chrony/drift
  133. # Allow the system clock to be stepped in the first three updates
  134. # if its offset is larger than 1 second.
  135. makestep 1.0 3
  136. # Enable kernel synchronization of the real-time clock (RTC).
  137. rtcsync
  138. # Enable hardware timestamping on all interfaces that support it.
  139. #hwtimestamp *
  140. # Increase the minimum number of selectable sources required to adjust
  141. # the system clock.
  142. #minsources 2
  143. # Allow NTP client access from local network.
  144. #allow 192.168.0.0/16
  145. allow all
  146. bindcmdaddress 0.0.0.0
  147. cmdallow all
  148. # Serve time even if not synchronized to a time source.
  149. #local stratum 10
  150. # Specify file containing keys for NTP authentication.
  151. keyfile /etc/chrony.keys
  152. # Get TAI-UTC offset and leap seconds from the system tz database.
  153. leapsectz right/UTC
  154. # Specify directory for log files.
  155. logdir /var/log/chrony
  156. # Select which information is logged.
  157. #log measurements statistics tracking
  158. notify:
  159. - restart chronyd
  160. - name: Ensure firewall allows NTP.
  161. become: yes
  162. ansible.posix.firewalld:
  163. immediate: yes
  164. permanent: yes
  165. zone: "{{ item }}"
  166. service: ntp
  167. state: enabled
  168. loop:
  169. - external
  170. - public
  171. - name: Ensure firewall allows cmdport.
  172. become: yes
  173. ansible.posix.firewalld:
  174. immediate: yes
  175. permanent: yes
  176. zone: "{{ item }}"
  177. port: 323/udp
  178. state: enabled
  179. loop:
  180. - external
  181. - public
  182. handlers:
  183. - name: restart chronyd
  184. become: yes
  185. ansible.builtin.service:
  186. name: chronyd
  187. state: restarted
  188. ...