Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

268 lignes
9.0 KiB

  1. ---
  2. - name: Enable index.html creation if user doesn't wish to customise base domain
  3. delegate_to: 127.0.0.1
  4. lineinfile:
  5. path: '{{ awx_cached_matrix_vars }}'
  6. regexp: "^#? *{{ item.key | regex_escape() }}:"
  7. line: "{{ item.key }}: {{ item.value }}"
  8. insertafter: '# Base Domain Settings Start'
  9. with_dict:
  10. 'matrix_nginx_proxy_base_domain_homepage_enabled': 'true'
  11. when: (awx_customise_base_domain_website is defined) and not awx_customise_base_domain_website|bool
  12. - name: Disable index.html creation to allow multi-file site if user does wish to customise base domain
  13. delegate_to: 127.0.0.1
  14. lineinfile:
  15. path: '{{ awx_cached_matrix_vars }}'
  16. regexp: "^#? *{{ item.key | regex_escape() }}:"
  17. line: "{{ item.key }}: {{ item.value }}"
  18. insertafter: '# Base Domain Settings Start'
  19. with_dict:
  20. 'matrix_nginx_proxy_base_domain_homepage_enabled': 'false'
  21. when: (awx_customise_base_domain_website is defined) and awx_customise_base_domain_website|bool
  22. - name: Record custom 'Customise Website + Access Export' variables locally on AWX
  23. delegate_to: 127.0.0.1
  24. lineinfile:
  25. path: '{{ awx_cached_matrix_vars }}'
  26. regexp: "^#? *{{ item.key | regex_escape() }}:"
  27. line: "{{ item.key }}: {{ item.value }}"
  28. insertafter: '# Custom Settings Start'
  29. with_dict:
  30. 'awx_sftp_auth_method': '"{{ awx_sftp_auth_method }}"'
  31. 'awx_sftp_password': '"{{ awx_sftp_password }}"'
  32. 'awx_sftp_public_key': '"{{ awx_sftp_public_key }}"'
  33. - name: Record custom 'Customise Website + Access Export' variables locally on AWX
  34. delegate_to: 127.0.0.1
  35. lineinfile:
  36. path: '{{ awx_cached_matrix_vars }}'
  37. regexp: "^#? *{{ item.key | regex_escape() }}:"
  38. line: "{{ item.key }}: {{ item.value }}"
  39. insertafter: '# Custom Settings Start'
  40. with_dict:
  41. 'awx_customise_base_domain_website': '{{ awx_customise_base_domain_website }}'
  42. when: awx_customise_base_domain_website is defined
  43. - name: Reload vars in matrix_vars.yml
  44. include_vars:
  45. file: '{{ awx_cached_matrix_vars }}'
  46. no_log: true
  47. - name: Save new 'Customise Website + Access Export' survey.json to the AWX tower, template
  48. delegate_to: 127.0.0.1
  49. template:
  50. src: './roles/matrix-awx/surveys/configure_website_access_export.json.j2'
  51. dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json'
  52. when: awx_customise_base_domain_website is defined
  53. - name: Copy new 'Customise Website + Access Export' survey.json to target machine
  54. copy:
  55. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json'
  56. dest: '/matrix/awx/configure_website_access_export.json'
  57. mode: '0660'
  58. when: awx_customise_base_domain_website is defined
  59. - name: Save new 'Customise Website + Access Export' survey.json to the AWX tower, template
  60. delegate_to: 127.0.0.1
  61. template:
  62. src: './roles/matrix-awx/surveys/access_export.json.j2'
  63. dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/access_export.json'
  64. when: awx_customise_base_domain_website is undefined
  65. - name: Copy new 'Customise Website + Access Export' survey.json to target machine
  66. copy:
  67. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/access_export.json'
  68. dest: '/matrix/awx/access_export.json'
  69. mode: '0660'
  70. when: awx_customise_base_domain_website is undefined
  71. - name: Recreate 'Configure Website + Access Export' job template
  72. delegate_to: 127.0.0.1
  73. awx.awx.tower_job_template:
  74. name: "{{ matrix_domain }} - 1 - Configure Website + Access Export"
  75. description: "Configure base domain website settings and access the servers export."
  76. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  77. job_type: run
  78. job_tags: "start,setup-nginx-proxy"
  79. inventory: "{{ member_id }}"
  80. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  81. playbook: setup.yml
  82. credential: "{{ member_id }} - AWX SSH Key"
  83. survey_enabled: true
  84. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json') }}"
  85. become_enabled: true
  86. state: present
  87. verbosity: 1
  88. tower_host: "https://{{ awx_host }}"
  89. tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
  90. validate_certs: true
  91. when: awx_customise_base_domain_website is defined
  92. - name: Recreate 'Access Export' job template
  93. delegate_to: 127.0.0.1
  94. awx.awx.tower_job_template:
  95. name: "{{ matrix_domain }} - 1 - Access Export"
  96. description: "Access the services export."
  97. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  98. job_type: run
  99. job_tags: "start,setup-nginx-proxy"
  100. inventory: "{{ member_id }}"
  101. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  102. playbook: setup.yml
  103. credential: "{{ member_id }} - AWX SSH Key"
  104. survey_enabled: true
  105. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/access_export.json') }}"
  106. become_enabled: true
  107. state: present
  108. verbosity: 1
  109. tower_host: "https://{{ awx_host }}"
  110. tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
  111. validate_certs: true
  112. when: awx_customise_base_domain_website is undefined
  113. - name: If user doesn't define a awx_sftp_password, create a disabled 'sftp' account
  114. user:
  115. name: sftp
  116. comment: SFTP user to set custom web files and access servers export
  117. shell: /bin/false
  118. home: /home/sftp
  119. group: matrix
  120. password: '*'
  121. update_password: always
  122. when: awx_sftp_password|length == 0
  123. - name: If user defines awx_sftp_password, enable account and set password on 'stfp' account
  124. user:
  125. name: sftp
  126. comment: SFTP user to set custom web files and access servers export
  127. shell: /bin/false
  128. home: /home/sftp
  129. group: matrix
  130. password: "{{ awx_sftp_password | password_hash('sha512') }}"
  131. update_password: always
  132. when: awx_sftp_password|length > 0
  133. - name: Ensure group "sftp" exists
  134. group:
  135. name: sftp
  136. state: present
  137. - name: adding existing user 'sftp' to group matrix
  138. user:
  139. name: sftp
  140. groups: sftp
  141. append: true
  142. when: awx_customise_base_domain_website is defined
  143. - name: Create the ro /chroot directory with sticky bit if it doesn't exist. (/chroot/website has matrix:matrix permissions and is mounted to nginx container)
  144. file:
  145. path: /chroot
  146. state: directory
  147. owner: root
  148. group: root
  149. mode: '1755'
  150. - name: Ensure /chroot/website location exists.
  151. file:
  152. path: /chroot/website
  153. state: directory
  154. owner: matrix
  155. group: matrix
  156. mode: '0770'
  157. when: awx_customise_base_domain_website is defined
  158. - name: Ensure /chroot/export location exists
  159. file:
  160. path: /chroot/export
  161. state: directory
  162. owner: sftp
  163. group: sftp
  164. mode: '0700'
  165. - name: Ensure /home/sftp/.ssh location exists
  166. file:
  167. path: /home/sftp/.ssh
  168. state: directory
  169. owner: sftp
  170. group: sftp
  171. mode: '0700'
  172. - name: Ensure /home/sftp/authorized_keys exists
  173. file:
  174. path: /home/sftp/.ssh/authorized_keys
  175. state: touch
  176. owner: sftp
  177. group: sftp
  178. mode: '0644'
  179. - name: Clear authorized_keys file
  180. shell: echo "" > /home/sftp/.ssh/authorized_keys
  181. - name: Insert public SSH key into authorized_keys file
  182. lineinfile:
  183. path: /home/sftp/.ssh/authorized_keys
  184. line: "{{ awx_sftp_public_key }}"
  185. owner: sftp
  186. group: sftp
  187. mode: '0644'
  188. when: (awx_sftp_public_key | length > 0) and (awx_sftp_auth_method == "SSH Key")
  189. - name: Remove any existing Subsystem lines
  190. lineinfile:
  191. path: /etc/ssh/sshd_config
  192. state: absent
  193. regexp: '^Subsystem'
  194. - name: Set SSH Subsystem State
  195. lineinfile:
  196. path: /etc/ssh/sshd_config
  197. insertafter: "^# override default of no subsystems"
  198. line: "Subsystem sftp internal-sftp"
  199. - name: Add SSH Match User section for disabled auth
  200. blockinfile:
  201. path: /etc/ssh/sshd_config
  202. state: absent
  203. block: |
  204. Match User sftp
  205. ChrootDirectory /chroot
  206. PermitTunnel no
  207. X11Forwarding no
  208. AllowTcpForwarding no
  209. PasswordAuthentication yes
  210. AuthorizedKeysFile /home/sftp/.ssh/authorized_keys
  211. when: awx_sftp_auth_method == "Disabled"
  212. - name: Add SSH Match User section for password auth
  213. blockinfile:
  214. path: /etc/ssh/sshd_config
  215. state: present
  216. block: |
  217. Match User sftp
  218. ChrootDirectory /chroot
  219. PermitTunnel no
  220. X11Forwarding no
  221. AllowTcpForwarding no
  222. PasswordAuthentication yes
  223. when: awx_sftp_auth_method == "Password"
  224. - name: Add SSH Match User section for publickey auth
  225. blockinfile:
  226. path: /etc/ssh/sshd_config
  227. state: present
  228. block: |
  229. Match User sftp
  230. ChrootDirectory /chroot
  231. PermitTunnel no
  232. X11Forwarding no
  233. AllowTcpForwarding no
  234. AuthorizedKeysFile /home/sftp/.ssh/authorized_keys
  235. when: awx_sftp_auth_method == "SSH Key"
  236. - name: Restart service ssh.service
  237. service:
  238. name: ssh.service
  239. state: restarted