Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

101 строка
3.6 KiB

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