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

84 строки
3.0 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: Run export.sh if this job template is run by the client
  52. command: /bin/sh /root/export.sh
  53. tags: use-survey
  54. - name: Include vars in matrix_vars.yml
  55. include_vars:
  56. file: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  57. no_log: True
  58. - name: Copy new 'matrix_vars.yml' to target machine
  59. copy:
  60. src: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
  61. dest: '/matrix/awx/matrix_vars.yml'
  62. mode: '0660'
  63. tags: use-survey
  64. - name: Perform the borg backup
  65. command: borgmatic
  66. when: matrix_awx_backup_enabled|bool
  67. - name: Set boolean value to exit playbook
  68. set_fact:
  69. end_playbook: true
  70. - name: End playbook if this task list is called.
  71. meta: end_play
  72. when: end_playbook is defined and end_playbook|bool