Matrix Docker Ansible eploy
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

274 satır
9.2 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: Collect AWX admin token the hard way!
  71. delegate_to: 127.0.0.1
  72. shell: |
  73. curl -sku {{ tower_username }}:{{ tower_password }} -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"write"}' https://{{ tower_host }}/api/v2/users/1/personal_tokens/ | jq '.token' | sed -r 's/\"//g'
  74. register: tower_token
  75. no_log: True
  76. - name: Recreate 'Configure Website + Access Export' job template
  77. delegate_to: 127.0.0.1
  78. awx.awx.tower_job_template:
  79. name: "{{ matrix_domain }} - 1 - Configure Website + Access Export"
  80. description: "Configure base domain website settings and access the servers export."
  81. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  82. job_type: run
  83. job_tags: "start,setup-nginx-proxy"
  84. inventory: "{{ member_id }}"
  85. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  86. playbook: setup.yml
  87. credential: "{{ member_id }} - AWX SSH Key"
  88. survey_enabled: true
  89. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json') }}"
  90. become_enabled: yes
  91. state: present
  92. verbosity: 1
  93. tower_host: "https://{{ tower_host }}"
  94. tower_oauthtoken: "{{ tower_token.stdout }}"
  95. validate_certs: yes
  96. when: customise_base_domain_website is defined
  97. - name: Recreate 'Access Export' job template
  98. delegate_to: 127.0.0.1
  99. awx.awx.tower_job_template:
  100. name: "{{ matrix_domain }} - 1 - Access Export"
  101. description: "Access the services export."
  102. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  103. job_type: run
  104. job_tags: "start,setup-nginx-proxy"
  105. inventory: "{{ member_id }}"
  106. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  107. playbook: setup.yml
  108. credential: "{{ member_id }} - AWX SSH Key"
  109. survey_enabled: true
  110. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/access_export.json') }}"
  111. become_enabled: yes
  112. state: present
  113. verbosity: 1
  114. tower_host: "https://{{ tower_host }}"
  115. tower_oauthtoken: "{{ tower_token.stdout }}"
  116. validate_certs: yes
  117. when: customise_base_domain_website is undefined
  118. - name: Ensure group "sftp" exists
  119. group:
  120. name: sftp
  121. state: present
  122. - name: If user doesn't define a sftp_password, create a disabled 'sftp' 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: sftp
  129. password: '*'
  130. update_password: always
  131. when: sftp_password|length == 0
  132. - name: If user defines sftp_password, enable account and set password on 'stfp' account
  133. user:
  134. name: sftp
  135. comment: SFTP user to set custom web files and access servers export
  136. shell: /bin/false
  137. home: /home/sftp
  138. group: sftp
  139. password: "{{ sftp_password | password_hash('sha512') }}"
  140. update_password: always
  141. when: sftp_password|length > 0
  142. - name: adding existing user 'sftp' to group matrix
  143. user:
  144. name: sftp
  145. groups: matrix
  146. append: yes
  147. when: customise_base_domain_website is defined
  148. - 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)
  149. file:
  150. path: /chroot
  151. state: directory
  152. owner: root
  153. group: root
  154. mode: '1755'
  155. - name: Ensure /chroot/website location exists.
  156. file:
  157. path: /chroot/website
  158. state: directory
  159. owner: matrix
  160. group: matrix
  161. mode: '0574'
  162. when: customise_base_domain_website is defined
  163. - name: Ensure /chroot/export location exists
  164. file:
  165. path: /chroot/export
  166. state: directory
  167. owner: sftp
  168. group: sftp
  169. mode: '0700'
  170. - name: Ensure /home/sftp/.ssh location exists
  171. file:
  172. path: /home/sftp/.ssh
  173. state: directory
  174. owner: sftp
  175. group: sftp
  176. mode: '0700'
  177. - name: Ensure /home/sftp/authorized_keys exists
  178. file:
  179. path: /home/sftp/.ssh/authorized_keys
  180. state: touch
  181. owner: sftp
  182. group: sftp
  183. mode: '0644'
  184. - name: Clear authorized_keys file
  185. shell: echo "" > /home/sftp/.ssh/authorized_keys
  186. - name: Insert public SSH key into authorized_keys file
  187. lineinfile:
  188. path: /home/sftp/.ssh/authorized_keys
  189. line: "{{ sftp_public_key }}"
  190. owner: sftp
  191. group: sftp
  192. mode: '0644'
  193. when: (sftp_public_key | length > 0) and (sftp_auth_method == "SSH Key")
  194. - name: Alter SSH Subsystem State 1
  195. lineinfile:
  196. path: /etc/ssh/sshd_config
  197. line: "Subsystem sftp /usr/lib/openssh/sftp-server"
  198. state: absent
  199. - name: Alter SSH Subsystem State 2
  200. lineinfile:
  201. path: /etc/ssh/sshd_config
  202. insertafter: "^# override default of no subsystems"
  203. line: "Subsystem sftp internal-sftp"
  204. - name: Add SSH Match User section for disabled auth
  205. blockinfile:
  206. path: /etc/ssh/sshd_config
  207. state: absent
  208. block: |
  209. Match User sftp
  210. ChrootDirectory /chroot
  211. PermitTunnel no
  212. X11Forwarding no
  213. AllowTcpForwarding no
  214. PasswordAuthentication yes
  215. AuthorizedKeysFile /home/sftp/.ssh/authorized_keys
  216. when: sftp_auth_method == "Disabled"
  217. - name: Add SSH Match User section for password auth
  218. blockinfile:
  219. path: /etc/ssh/sshd_config
  220. state: present
  221. block: |
  222. Match User sftp
  223. ChrootDirectory /chroot
  224. PermitTunnel no
  225. X11Forwarding no
  226. AllowTcpForwarding no
  227. PasswordAuthentication yes
  228. when: sftp_auth_method == "Password"
  229. - name: Add SSH Match User section for publickey auth
  230. blockinfile:
  231. path: /etc/ssh/sshd_config
  232. state: present
  233. block: |
  234. Match User sftp
  235. ChrootDirectory /chroot
  236. PermitTunnel no
  237. X11Forwarding no
  238. AllowTcpForwarding no
  239. AuthorizedKeysFile /home/sftp/.ssh/authorized_keys
  240. when: sftp_auth_method == "SSH Key"
  241. - name: Restart service ssh.service
  242. service:
  243. name: ssh.service
  244. state: restarted