30-quay-pre-tasks.yml 6.4 KB

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