Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

267 rivejä
8.9 KiB

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