Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

102 righe
3.6 KiB

  1. ---
  2. - name: Record Backup Server variables locally on AWX
  3. delegate_to: 127.0.0.1
  4. lineinfile:
  5. path: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  6. regexp: "^#? *{{ item.key | regex_escape() }}:"
  7. line: "{{ item.key }}: {{ item.value }}"
  8. insertafter: '# AWX Settings Start'
  9. with_dict:
  10. 'awx_backup_enabled': '{{ awx_backup_enabled }}'
  11. tags: use-survey
  12. - name: Save new 'Backup Server' survey.json to the AWX tower, template
  13. delegate_to: 127.0.0.1
  14. template:
  15. src: 'roles/matrix-awx/surveys/backup_server.json.j2'
  16. dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json'
  17. tags: use-survey
  18. - name: Copy new 'Backup Server' survey.json to target machine
  19. copy:
  20. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json'
  21. dest: '/matrix/awx/backup_server.json'
  22. mode: '0660'
  23. tags: use-survey
  24. - name: Recreate 'Backup Server' job template
  25. delegate_to: 127.0.0.1
  26. awx.awx.tower_job_template:
  27. name: "{{ matrix_domain }} - 0 - Backup Server"
  28. description: "Performs a backup of the entire service to a remote location."
  29. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  30. job_type: run
  31. job_tags: "backup-server,use-survey"
  32. inventory: "{{ member_id }}"
  33. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  34. playbook: setup.yml
  35. credential: "{{ member_id }} - AWX SSH Key"
  36. survey_enabled: true
  37. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json') }}"
  38. become_enabled: true
  39. state: present
  40. verbosity: 1
  41. tower_host: "https://{{ awx_host }}"
  42. tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
  43. validate_certs: true
  44. tags: use-survey
  45. - name: Include vars in matrix_vars.yml
  46. include_vars:
  47. file: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  48. no_log: true
  49. - name: Copy new 'matrix_vars.yml' to target machine
  50. copy:
  51. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  52. dest: '/matrix/awx/matrix_vars.yml'
  53. mode: '0660'
  54. tags: use-survey
  55. - name: Run initial backup of /matrix/ and snapshot the database simultaneously
  56. command: "{{ item }}"
  57. with_items:
  58. - borgmatic -c /root/.config/borgmatic/config_1.yaml
  59. - /bin/sh /usr/local/bin/awx-export-service.sh 1 0
  60. register: _create_instances
  61. async: 3600 # Maximum runtime in seconds.
  62. poll: 0 # Fire and continue (never poll)
  63. when: awx_backup_enabled|bool
  64. - name: Wait for both of these jobs to finish
  65. async_status:
  66. jid: "{{ item.ansible_job_id }}"
  67. register: _jobs
  68. until: _jobs.finished
  69. delay: 5 # Check every 5 seconds.
  70. retries: 720 # Retry for a full hour.
  71. with_items: "{{ _create_instances.results }}"
  72. when: awx_backup_enabled|bool
  73. - name: Perform borg backup of postgres dump
  74. command: borgmatic -c /root/.config/borgmatic/config_2.yaml
  75. when: awx_backup_enabled|bool
  76. - name: Delete the AWX session token for executing modules
  77. awx.awx.tower_token:
  78. description: 'AWX Session Token'
  79. scope: "write"
  80. state: absent
  81. existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
  82. tower_host: "https://{{ awx_host }}"
  83. tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
  84. - name: Set boolean value to exit playbook
  85. set_fact:
  86. awx_end_playbook: true
  87. - name: End playbook if this task list is called.
  88. meta: end_play
  89. when: awx_end_playbook is defined and awx_end_playbook|bool