Remove Mattermost information.
This commit is contained in:
231
semaphore.yaml
231
semaphore.yaml
@@ -5,145 +5,116 @@
|
|||||||
gather_facts: true
|
gather_facts: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Cleanup semaphore
|
- name: Include variables
|
||||||
block:
|
include_vars: vars/semaphore.yaml
|
||||||
- include_vars: vars/mattermost.yaml
|
|
||||||
- include_vars: vars/semaphore.yaml
|
|
||||||
|
|
||||||
- name: Search for volume's backup directories
|
- name: Search for volume's backup directories
|
||||||
become: yes
|
become: yes
|
||||||
find:
|
find:
|
||||||
paths: "{{ local_backup }}"
|
paths: "{{ local_backup }}"
|
||||||
file_type: directory
|
file_type: directory
|
||||||
recurse: false
|
recurse: false
|
||||||
register: backup_dirs
|
register: backup_dirs
|
||||||
|
|
||||||
- name: Copy backup files
|
- name: Copy backup files
|
||||||
become: yes
|
become: yes
|
||||||
copy:
|
copy:
|
||||||
remote_src: true
|
remote_src: true
|
||||||
src: "{{ item.path }}"
|
src: "{{ item.path }}"
|
||||||
dest: "{{ backup_dir }}"
|
dest: "{{ backup_dir }}"
|
||||||
loop: "{{ backup_dirs.files }}"
|
loop: "{{ backup_dirs.files }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Cleanup volume's backup directories
|
- name: Cleanup volume's backup directories
|
||||||
become: yes
|
become: yes
|
||||||
file:
|
file:
|
||||||
path: "{{ item.path }}"
|
path: "{{ item.path }}"
|
||||||
state: absent
|
state: absent
|
||||||
loop: "{{ backup_dirs.files }}"
|
loop: "{{ backup_dirs.files }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Correct directory owner
|
- name: Correct directory owner
|
||||||
become: yes
|
become: yes
|
||||||
file:
|
file:
|
||||||
path: "{{ backup_dir }}"
|
path: "{{ backup_dir }}"
|
||||||
owner: chris
|
owner: chris
|
||||||
group: chris
|
group: chris
|
||||||
recurse: yes
|
recurse: yes
|
||||||
|
|
||||||
- name: Register new backup directories
|
- name: Register new backup directories
|
||||||
find:
|
find:
|
||||||
paths: "{{ backup_dir }}"
|
paths: "{{ backup_dir }}"
|
||||||
file_type: directory
|
file_type: directory
|
||||||
recurse: false
|
recurse: false
|
||||||
register: backup_dirs
|
register: backup_dirs
|
||||||
|
|
||||||
- name: Check logrotate directories
|
- name: Check logrotate directories
|
||||||
file:
|
file:
|
||||||
path: "{{ item[0].path }}/{{ item[1] }}"
|
path: "{{ item[0].path }}/{{ item[1] }}"
|
||||||
state: directory
|
state: directory
|
||||||
with_nested:
|
with_nested:
|
||||||
- "{{ backup_dirs.files }}"
|
- "{{ backup_dirs.files }}"
|
||||||
- ['daily', 'weekly', 'monthly', 'yearly']
|
- ['daily', 'weekly', 'monthly', 'yearly']
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item[0].path }} {{ item[1] }}"
|
label: "{{ item[0].path }} {{ item[1] }}"
|
||||||
|
|
||||||
- name: Search for the created backups
|
- name: Search for the created backups
|
||||||
find:
|
find:
|
||||||
paths: "{{ item.path }}"
|
paths: "{{ item.path }}"
|
||||||
file_type: file
|
file_type: file
|
||||||
patterns: '*.gz'
|
patterns: '*.gz'
|
||||||
recurse: false
|
recurse: false
|
||||||
register: backup_files
|
register: backup_files
|
||||||
loop: "{{ backup_dirs.files }}"
|
loop: "{{ backup_dirs.files }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Store the yearly backups
|
- name: Store the yearly backups
|
||||||
copy:
|
copy:
|
||||||
remote_src: true
|
remote_src: true
|
||||||
src: "{{ item.path }}"
|
src: "{{ item.path }}"
|
||||||
dest: "{{ item.path | dirname }}/yearly/{{ item.path | basename }}"
|
dest: "{{ item.path | dirname }}/yearly/{{ item.path | basename }}"
|
||||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||||
when: (ansible_date_time.day == "01" and ansible_date_time.month == "01")
|
when: (ansible_date_time.day == "01" and ansible_date_time.month == "01")
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Store the monthly backups
|
- name: Store the monthly backups
|
||||||
copy:
|
copy:
|
||||||
remote_src: true
|
remote_src: true
|
||||||
src: "{{ item.path }}"
|
src: "{{ item.path }}"
|
||||||
dest: "{{ item.path | dirname }}/monthly/{{ item.path | basename }}"
|
dest: "{{ item.path | dirname }}/monthly/{{ item.path | basename }}"
|
||||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||||
when: (ansible_date_time.day == "01" and ansible_date_time.month != "01")
|
when: (ansible_date_time.day == "01" and ansible_date_time.month != "01")
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Store the weekly backups
|
- name: Store the weekly backups
|
||||||
copy:
|
copy:
|
||||||
remote_src: true
|
remote_src: true
|
||||||
src: "{{ item.path }}"
|
src: "{{ item.path }}"
|
||||||
dest: "{{ item.path | dirname }}/weekly/{{ item.path | basename }}"
|
dest: "{{ item.path | dirname }}/weekly/{{ item.path | basename }}"
|
||||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||||
when: (ansible_date_time.weekday_number == "1")
|
when: (ansible_date_time.weekday_number == "1")
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Store the daily backup
|
- name: Store the daily backup
|
||||||
copy:
|
copy:
|
||||||
remote_src: true
|
remote_src: true
|
||||||
src: "{{ item.path }}"
|
src: "{{ item.path }}"
|
||||||
dest: "{{ item.path | dirname }}/daily/{{ item.path | basename }}"
|
dest: "{{ item.path | dirname }}/daily/{{ item.path | basename }}"
|
||||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||||
when: (ansible_date_time.weekday_number != "1" and ansible_date_time.day != "01")
|
when: (ansible_date_time.weekday_number != "1" and ansible_date_time.day != "01")
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Cleanup original backup files
|
- name: Cleanup original backup files
|
||||||
file:
|
file:
|
||||||
path: "{{ item.path }}"
|
path: "{{ item.path }}"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
with_items: "{{ backup_files.results | map(attribute='files') | list }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.path }}"
|
label: "{{ item.path }}"
|
||||||
|
|
||||||
- name: Inform Mattermost about success
|
|
||||||
uri:
|
|
||||||
url: "{{ mattermost_url }}"
|
|
||||||
method: POST
|
|
||||||
body_format: json
|
|
||||||
body:
|
|
||||||
channel_id: "{{ channel_id }}"
|
|
||||||
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran successful ({{ ansible_play_name }})"
|
|
||||||
headers:
|
|
||||||
Content-Type: application/json
|
|
||||||
Authorization: "Bearer {{ semaphore_token }}"
|
|
||||||
status_code: [200, 201]
|
|
||||||
|
|
||||||
rescue:
|
|
||||||
- name: Inform Mattermost about error
|
|
||||||
uri:
|
|
||||||
url: "{{ mattermost_url }}"
|
|
||||||
method: POST
|
|
||||||
body_format: json
|
|
||||||
body:
|
|
||||||
channel_id: "{{ channel_id }}"
|
|
||||||
message: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}: Playbook ran with error ({{ ansible_play_name }})"
|
|
||||||
headers:
|
|
||||||
Content-Type: application/json
|
|
||||||
Authorization: "Bearer {{ error_token }}"
|
|
||||||
status_code: [200, 201]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user