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.
 
 

69 lines
2.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'
  8. with_dict:
  9. 'matrix_awx_backup_enabled': '{{ matrix_awx_backup_enabled }}'
  10. - name: Copy new 'matrix_vars.yml' to target machine
  11. copy:
  12. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  13. dest: '/matrix/awx/matrix_vars.yml'
  14. mode: '0660'
  15. - name: Save new 'Backup Server' survey.json to the AWX tower, template
  16. delegate_to: 127.0.0.1
  17. template:
  18. src: 'roles/matrix-awx/surveys/backup_server.json.j2'
  19. dest: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json'
  20. - name: Copy new 'Backup Server' survey.json to target machine
  21. copy:
  22. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json'
  23. dest: '/matrix/awx/backup_server.json'
  24. mode: '0660'
  25. - name: Collect AWX admin token the hard way!
  26. delegate_to: 127.0.0.1
  27. shell: |
  28. 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'
  29. register: tower_token
  30. no_log: True
  31. - name: Recreate 'Backup Server' job template
  32. delegate_to: 127.0.0.1
  33. awx.awx.tower_job_template:
  34. name: "{{ matrix_domain }} - 0 - Backup Server"
  35. description: "Performs a backup of the entire service to a remote location."
  36. extra_vars: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/extra_vars.json') }}"
  37. job_type: run
  38. job_tags: "backup-server"
  39. inventory: "{{ member_id }}"
  40. project: "{{ member_id }} - Matrix Docker Ansible Deploy"
  41. playbook: setup.yml
  42. credential: "{{ member_id }} - AWX SSH Key"
  43. survey_enabled: true
  44. survey_spec: "{{ lookup('file', '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/backup_server.json') }}"
  45. become_enabled: yes
  46. state: present
  47. verbosity: 1
  48. tower_host: "https://{{ tower_host }}"
  49. tower_oauthtoken: "{{ tower_token.stdout }}"
  50. validate_certs: yes
  51. - name: Perform the borg backup
  52. command: borgmatic
  53. when: matrix_awx_backup_enabled|bool
  54. - name: Set boolean value to exit playbook
  55. set_fact:
  56. end_playbook: true
  57. - name: End playbook if this task list is called.
  58. meta: end_play
  59. when: end_playbook is defined and end_playbook|bool