33-clair-deploy.yml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. ---
  2. # Tasks required by 15-clair-deploy.adoc.
  3. - name: Prepare registry VM to run Clair services.
  4. hosts: registry.ocp4.example.com
  5. gather_subset: min
  6. remote_user: quay
  7. tasks:
  8. - name: Ensure the podman network is there.
  9. containers.podman.podman_network_info:
  10. name: quay
  11. register: quay_net
  12. ignore_errors: yes
  13. - ansible.builtin.assert:
  14. that:
  15. - not quay_net.failed
  16. - quay_net.networks is defined
  17. - quay_net.networks is iterable
  18. - quay_net.networks | length == 1
  19. fail_msg: "FATAL: Podman network 'quay' does not exist for 'quay' user. Ensure you deployed Quay before running this playbook."
  20. success_msg: "OK, network 'quay' found."
  21. - name: Ensure the quay service is defined.
  22. ansible.builtin.stat:
  23. path: "{{ ansible_facts['user_dir'] }}/.config/systemd/user/quay.service"
  24. get_attributes: no
  25. get_checksum: no
  26. get_mime: no
  27. register: quay_svc_unit
  28. - ansible.builtin.assert:
  29. that:
  30. - not quay_svc_unit.failed
  31. - quay_svc_unit.stat.exists
  32. fail_msg: "FATAL: User service 'quay.service' not found for 'quay' user. Ensure you deployed Quay before running this playbook."
  33. success_msg: "OK, service 'quay.service' found."
  34. - name: Ensure the quay-pg service is defined.
  35. ansible.builtin.stat:
  36. path: "{{ ansible_facts['user_dir'] }}/.config/systemd/user/quay-pg.service"
  37. get_attributes: no
  38. get_checksum: no
  39. get_mime: no
  40. register: quay_pg_svc_unit
  41. - ansible.builtin.assert:
  42. that:
  43. - not quay_pg_svc_unit.failed
  44. - quay_pg_svc_unit.stat.exists
  45. fail_msg: "FATAL: User service 'quay-pg.service' not found for 'quay' user. Ensure you deployed Quay before running this playbook."
  46. success_msg: "OK, service 'quay-pg.service' found."
  47. - name: Ensure Quay PostgreSQL is running.
  48. ansible.builtin.systemd_service:
  49. name: quay-pg
  50. scope: user
  51. state: started
  52. - name: Check whether the clair database exists.
  53. containers.podman.podman_container_exec:
  54. name: postgresql
  55. command: psql -d postgres -U postgres -t -A -c "SELECT datname FROM pg_database WHERE datname = 'clair'"
  56. register: pg_clair
  57. changed_when: no
  58. - name: Create the clair database if necessary.
  59. containers.podman.podman_container_exec:
  60. name: postgresql
  61. command: 'psql -d postgres -U postgres -c "CREATE DATABASE clair OWNER quay"'
  62. when:
  63. - pg_clair is defined
  64. - pg_clair.stdout_lines | length == 0
  65. - name: Create the uuid-ossp extension if necessary.
  66. containers.podman.podman_container_exec:
  67. name: postgresql
  68. command: psql -d clair -U postgres -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"'
  69. register: pg_ext
  70. changed_when:
  71. - not "already exists" in pg_ext.stderr
  72. # TODO: Make loop labels nicer.
  73. - name: Patch Quay config if necessary.
  74. ansible.builtin.lineinfile:
  75. path: "{{ ansible_facts['user_dir'] }}/config/config.yaml"
  76. insertafter: "{{ item.after }}"
  77. regexp: "{{ item.fixre }}"
  78. line: "{{ item.value }}"
  79. loop:
  80. - after: "^FEATURE_MAILING: false$"
  81. fixre: "^FEATURE_SECURITY_SCANNER: .*$"
  82. value: "FEATURE_SECURITY_SCANNER: true"
  83. - after: "^SECRET_KEY: .*$"
  84. fixre: "^SECURITY_SCANNER_INDEXING_INTERVAL: .*$"
  85. value: "SECURITY_SCANNER_INDEXING_INTERVAL: 30"
  86. - after: "^SECURITY_SCANNER_INDEXING_INTERVAL: .*$"
  87. fixre: "^SECURITY_SCANNER_V4_PSK: .*$"
  88. value: "SECURITY_SCANNER_V4_PSK: NjA1aWhnNWk4MWhqNw=="
  89. - after: "^SECURITY_SCANNER_V4_PSK: .*$"
  90. fixre: "^SECURITY_SCANNER_V4_ENDPOINT: .*$"
  91. value: "SECURITY_SCANNER_V4_ENDPOINT: http://clair:8081"
  92. notify:
  93. - restart quay and wait for ready
  94. - name: Create Clair config directory if necessary.
  95. ansible.builtin.file:
  96. path: "{{ ansible_facts['user_dir'] }}/clair"
  97. state: directory
  98. mode: 0775
  99. - name: Publish Clair config if necessary.
  100. ansible.builtin.copy:
  101. dest: "{{ ansible_facts['user_dir'] }}/clair/config.yaml"
  102. content: |
  103. http_listen_addr: :8081
  104. introspection_addr: :8088
  105. log_level: debug
  106. indexer:
  107. connstring: host=postgresql port=5432 dbname=clair user=quay password=secret sslmode=disable
  108. scanlock_retry: 10
  109. layer_scan_concurrency: 5
  110. migrations: true
  111. matcher:
  112. connstring: host=postgresql port=5432 dbname=clair user=quay password=secret sslmode=disable
  113. max_conn_pool: 100
  114. migrations: true
  115. indexer_addr: clair-indexer
  116. notifier:
  117. connstring: host=postgresql port=5432 dbname=clair user=quay password=secret sslmode=disable
  118. delivery_interval: 1m
  119. poll_interval: 5m
  120. migrations: true
  121. auth:
  122. psk:
  123. key: "NjA1aWhnNWk4MWhqNw=="
  124. iss: ["quay"]
  125. metrics:
  126. name: "prometheus"
  127. mode: 0664
  128. notify:
  129. - restart quay and wait for ready
  130. - restart clair
  131. - name: Ensure same TLS trust will be used for Clair as for workstation.
  132. ansible.builtin.copy:
  133. src: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
  134. dest: "{{ ansible_facts['user_dir'] }}/tls-ca-bundle.pem"
  135. mode: 0664
  136. notify:
  137. - restart clair
  138. - name: Ensure Clair service unit is there.
  139. ansible.builtin.template:
  140. dest: "{{ ansible_facts['user_dir'] }}/.config/systemd/user/clair.service"
  141. src: "templates/clair.service.j2"
  142. - name: Reload systemd.
  143. ansible.builtin.systemd_service:
  144. daemon_reload: yes
  145. scope: user
  146. - name: Enable services and start them.
  147. ansible.builtin.systemd_service:
  148. name: clair
  149. scope: user
  150. state: started
  151. enabled: yes
  152. handlers:
  153. - name: restart quay
  154. listen: restart quay and wait for ready
  155. ansible.builtin.systemd_service:
  156. name: quay
  157. scope: user
  158. state: restarted
  159. - name: wait for quay to become ready again
  160. listen: restart quay and wait for ready
  161. ansible.builtin.uri:
  162. method: GET
  163. url: https://registry.ocp4.example.com/
  164. headers:
  165. Accept: application/json
  166. Content-Type: application/json
  167. validate_certs: no
  168. status_code:
  169. - 200
  170. - 404
  171. - 502
  172. register: startup_wait
  173. until: startup_wait.status == 200
  174. retries: 30
  175. delay: 5
  176. - name: restart clair
  177. ansible.builtin.systemd_service:
  178. name: clair
  179. scope: user
  180. state: restarted
  181. ...