Matrix Docker Ansible eploy
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

100 linhas
3.7 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. 'matrix_awx_backup_enabled': '{{ matrix_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: Collect AWX admin token the hard way!
  24. delegate_to: 127.0.0.1
  25. shell: |
  26. 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'
  27. register: tower_token
  28. no_log: True
  29. tags: use-survey
  30. - name: Recreate 'Backup Server' job template
  31. delegate_to: 127.0.0.1
  32. awx.awx.tower_job_template:
  33. name: "{{ matrix_domain }} - 0 - Backup Server"
  34. description: "Performs a backup of the entire service to a remote location."
  35. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  36. job_type: run
  37. job_tags: "backup-server,use-survey"
  38. inventory: "{{ member_id }}"
  39. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  40. playbook: setup.yml
  41. credential: "{{ member_id }} - AWX SSH Key"
  42. survey_enabled: true
  43. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json') }}"
  44. become_enabled: yes
  45. state: present
  46. verbosity: 1
  47. tower_host: "https://{{ tower_host }}"
  48. tower_oauthtoken: "{{ tower_token.stdout }}"
  49. validate_certs: yes
  50. tags: use-survey
  51. - name: Include vars in matrix_vars.yml
  52. include_vars:
  53. file: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  54. no_log: True
  55. - name: Copy new 'matrix_vars.yml' to target machine
  56. copy:
  57. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  58. dest: '/matrix/awx/matrix_vars.yml'
  59. mode: '0660'
  60. tags: use-survey
  61. - name: Run initial backup of /matrix/ and snapshot the database simultaneously
  62. command: "{{ item }}"
  63. with_items:
  64. - borgmatic -c /root/.config/borgmatic/config_1.yaml
  65. - /bin/sh /usr/local/bin/awx-export-service.sh 1 0
  66. register: _create_instances
  67. async: 3600 # Maximum runtime in seconds.
  68. poll: 0 # Fire and continue (never poll)
  69. when: matrix_awx_backup_enabled|bool
  70. - name: Wait for both of these jobs to finish
  71. async_status:
  72. jid: "{{ item.ansible_job_id }}"
  73. register: _jobs
  74. until: _jobs.finished
  75. delay: 5 # Check every 5 seconds.
  76. retries: 720 # Retry for a full hour.
  77. with_items: "{{ _create_instances.results }}"
  78. when: matrix_awx_backup_enabled|bool
  79. - name: Perform borg backup of postgres dump
  80. command: borgmatic -c /root/.config/borgmatic/config_2.yaml
  81. when: matrix_awx_backup_enabled|bool
  82. - name: Set boolean value to exit playbook
  83. set_fact:
  84. end_playbook: true
  85. - name: End playbook if this task list is called.
  86. meta: end_play
  87. when: end_playbook is defined and end_playbook|bool