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.
 
 

225 line
7.0 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|bool == false
  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|bool == true
  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. 'customise_base_domain_website': '{{ customise_base_domain_website }}'
  30. 'sftp_auth_method': '"{{ sftp_auth_method }}"'
  31. 'sftp_password': '"{{ sftp_password }}"'
  32. 'sftp_public_key': '"{{ sftp_public_key }}"'
  33. - name: Reload vars in matrix_vars.yml
  34. include_vars:
  35. file: '{{ awx_cached_matrix_vars }}'
  36. no_log: True
  37. # ^ Is this even needed?
  38. - name: Save new 'Customise Website + Access Export' survey.json to the AWX tower, template
  39. delegate_to: 127.0.0.1
  40. template:
  41. src: './roles/matrix-awx/surveys/configure_website_access_export.json.j2'
  42. dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json'
  43. - name: Copy new 'Customise Website + Access Export' survey.json to target machine
  44. copy:
  45. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json'
  46. dest: '/matrix/awx/configure_website_access_export.json'
  47. mode: '0660'
  48. - name: Collect AWX admin token the hard way!
  49. delegate_to: 127.0.0.1
  50. shell: |
  51. 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'
  52. register: tower_token
  53. no_log: True
  54. - name: Recreate 'Customise Base Domain Export' job template
  55. delegate_to: 127.0.0.1
  56. awx.awx.tower_job_template:
  57. name: "{{ matrix_domain }} - 1 - Configure Website + Access Export"
  58. description: "Configure base domain website settings and access the servers export."
  59. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  60. job_type: run
  61. job_tags: "start,setup-nginx-proxy"
  62. inventory: "{{ member_id }}"
  63. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  64. playbook: setup.yml
  65. credential: "{{ member_id }} - AWX SSH Key"
  66. survey_enabled: true
  67. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/configure_website_access_export.json') }}"
  68. become_enabled: yes
  69. state: present
  70. verbosity: 1
  71. tower_host: "https://{{ tower_host }}"
  72. tower_oauthtoken: "{{ tower_token.stdout }}"
  73. validate_certs: yes
  74. - name: Ensure group "sftp" exists
  75. group:
  76. name: sftp
  77. state: present
  78. - name: If user doesn't define a sftp_password, create a disabled 'sftp' account
  79. user:
  80. name: sftp
  81. comment: SFTP user to set custom web files and access servers export
  82. shell: /bin/false
  83. home: /home/sftp
  84. group: sftp
  85. password: '*'
  86. update_password: always
  87. when: sftp_password|length == 0
  88. - name: If user defines sftp_password, enable account and set password on 'stfp' account
  89. user:
  90. name: sftp
  91. comment: SFTP user to set custom web files and access servers export
  92. shell: /bin/false
  93. home: /home/sftp
  94. group: sftp
  95. password: "{{ sftp_password | password_hash('sha512') }}"
  96. update_password: always
  97. when: sftp_password|length > 0
  98. - name: adding existing user 'sftp' to group matrix
  99. user:
  100. name: sftp
  101. groups: matrix
  102. append: yes
  103. - 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)
  104. file:
  105. path: /chroot
  106. state: directory
  107. owner: root
  108. group: root
  109. mode: '1755'
  110. - name: Ensure /chroot/website location exists.
  111. file:
  112. path: /chroot/website
  113. state: directory
  114. owner: matrix
  115. group: matrix
  116. mode: '0574'
  117. - name: Ensure /chroot/export location exists
  118. file:
  119. path: /chroot/export
  120. state: directory
  121. owner: sftp
  122. group: sftp
  123. mode: '0700'
  124. - name: Ensure /home/sftp/.ssh location exists
  125. file:
  126. path: /home/sftp/.ssh
  127. state: directory
  128. owner: sftp
  129. group: sftp
  130. mode: '0700'
  131. - name: Ensure /home/sftp/authorized_keys exists
  132. file:
  133. path: /home/sftp/.ssh/authorized_keys
  134. state: touch
  135. owner: sftp
  136. group: sftp
  137. mode: '0644'
  138. - name: Clear authorized_keys file
  139. shell: echo "" > /home/sftp/.ssh/authorized_keys
  140. - name: Insert public SSH key into authorized_keys file
  141. lineinfile:
  142. path: /home/sftp/.ssh/authorized_keys
  143. line: "{{ sftp_public_key }}"
  144. owner: sftp
  145. group: sftp
  146. mode: '0644'
  147. when: (sftp_public_key | length > 0) and (sftp_auth_method == "SSH Key")
  148. - name: Alter SSH Subsystem State 1
  149. lineinfile:
  150. path: /etc/ssh/sshd_config
  151. line: "Subsystem sftp /usr/lib/openssh/sftp-server"
  152. state: absent
  153. - name: Alter SSH Subsystem State 2
  154. lineinfile:
  155. path: /etc/ssh/sshd_config
  156. insertafter: "^# override default of no subsystems"
  157. line: "Subsystem sftp internal-sftp"
  158. - name: Add SSH Match User section for disabled auth
  159. blockinfile:
  160. path: /etc/ssh/sshd_config
  161. state: absent
  162. block: |
  163. Match User sftp
  164. ChrootDirectory /chroot
  165. PermitTunnel no
  166. X11Forwarding no
  167. AllowTcpForwarding no
  168. PasswordAuthentication yes
  169. AuthorizedKeysFile /home/sftp/.ssh/authorized_keys
  170. when: sftp_auth_method == "Disabled"
  171. - name: Add SSH Match User section for password auth
  172. blockinfile:
  173. path: /etc/ssh/sshd_config
  174. state: present
  175. block: |
  176. Match User sftp
  177. ChrootDirectory /chroot
  178. PermitTunnel no
  179. X11Forwarding no
  180. AllowTcpForwarding no
  181. PasswordAuthentication yes
  182. when: sftp_auth_method == "Password"
  183. - name: Add SSH Match User section for publickey auth
  184. blockinfile:
  185. path: /etc/ssh/sshd_config
  186. state: present
  187. block: |
  188. Match User sftp
  189. ChrootDirectory /chroot
  190. PermitTunnel no
  191. X11Forwarding no
  192. AllowTcpForwarding no
  193. AuthorizedKeysFile /home/sftp/.ssh/authorized_keys
  194. when: sftp_auth_method == "SSH Key"
  195. - name: Restart service ssh.service
  196. service:
  197. name: ssh.service
  198. state: restarted