ansible/playbooks/sync_mailu.yaml

144 lines
4.5 KiB
YAML
Raw Normal View History

2023-08-22 10:05:14 +02:00
- hosts: containers
2023-08-22 10:03:54 +02:00
name: Stop mailu
2023-08-28 15:34:13 +02:00
ignore_unreachable: false
2023-08-30 10:49:49 +02:00
vars:
arch_name: docker_mailu2_data
2023-08-22 10:03:54 +02:00
tasks:
- name: Start mailu rasp
uri:
2023-08-30 10:25:18 +02:00
url: "http://192.168.77.106:9000/api/stacks/{{ item }}/start?endpointId=13"
2023-08-22 10:03:54 +02:00
method: POST
body_format: form-urlencoded
return_content: yes
headers:
Content-Type: "application/json"
X-API-Key: "ptr_DfS2M6Fj2P3fVvYpkhE0KJh2UGCzY47ePaFaLqadsjg="
timeout: 60
ignore_errors: yes
when: inventory_hostname in groups['nas']
2023-08-30 10:25:18 +02:00
loop:
- 130
- 149
2023-08-30 11:06:49 +02:00
#- 140
2023-08-30 11:15:27 +02:00
- 180
2023-08-22 10:03:54 +02:00
- name: Get ruleset
command: nvram get vts_rulelist
when: inventory_hostname in groups['router']
register: ruleset
2023-08-29 13:43:01 +02:00
- name: Pause for 60 seconds
2023-08-22 10:03:54 +02:00
ansible.builtin.pause:
2023-08-29 13:43:01 +02:00
seconds: 60
2023-08-22 10:03:54 +02:00
- name: Set new ruleset
command: nvram set vts_rulelist="{{ ruleset.stdout | replace('192.168.77.106', '192.168.77.246') }}"
when: inventory_hostname in groups['router']
- name: Test
command: nvram commit
when: inventory_hostname in groups['router']
- name: Restart firewall
command: service restart_firewall
when: inventory_hostname in groups['router']
2023-08-30 10:29:21 +02:00
args:
warn: false
2023-08-30 10:33:37 +02:00
2023-08-22 10:03:54 +02:00
- name: Stop mailu main
uri:
url: "http://192.168.77.106:9000/api/stacks/108/stop?endpointId=2"
method: POST
body_format: form-urlencoded
return_content: yes
headers:
Content-Type: "application/json"
X-API-Key: "ptr_DfS2M6Fj2P3fVvYpkhE0KJh2UGCzY47ePaFaLqadsjg="
timeout: 60
register: result
ignore_errors: yes
when: inventory_hostname in groups['nas']
- name: Create archive
#ansible.builtin.shell: 'tar -czf /share/Data/dockers.tar.gz /share/docker_data/{mailu2,webhub,ha} --exclude="/ha/backups/*" --exclude="home-assistant.log*"'
2023-08-30 10:49:49 +02:00
ansible.builtin.shell: 'tar -czf /share/Data/{{ arch_name }}-{{ ansible_date_time.date }}.tar.gz /share/docker_data/mailu2 --exclude="/ha/backups/*" --exclude="home-assistant.log*"'
2023-08-22 10:03:54 +02:00
ignore_errors: yes
2023-08-30 11:04:36 +02:00
args:
warn: false
2023-08-22 10:03:54 +02:00
when: inventory_hostname in groups['nas']
- name: Start mailu main
uri:
url: "http://192.168.77.106:9000/api/stacks/108/start?endpointId=2"
method: POST
body_format: form-urlencoded
return_content: yes
headers:
Content-Type: "application/json"
X-API-Key: "ptr_DfS2M6Fj2P3fVvYpkhE0KJh2UGCzY47ePaFaLqadsjg="
timeout: 60
ignore_errors: yes
when: inventory_hostname in groups['nas']
2023-08-29 14:20:14 +02:00
- name: Pause for 60 seconds
2023-08-22 10:03:54 +02:00
ansible.builtin.pause:
2023-08-29 14:20:14 +02:00
seconds: 60
2023-08-22 10:03:54 +02:00
#- debug:
# msg: "{{ ruleset.stdout }}"
- name: Set new ruleset
command: nvram set vts_rulelist="{{ ruleset.stdout | replace('192.168.77.246', '192.168.77.106') }}"
when: inventory_hostname in groups['router']
- name: Test
command: nvram commit
when: inventory_hostname in groups['router']
- name: Restart firewall
command: service restart_firewall
2023-08-29 15:15:21 +02:00
args:
warn: false
2023-08-29 14:56:35 +02:00
when: inventory_hostname in groups['router']
2023-08-22 10:03:54 +02:00
- name: Stop mailu rhasp
uri:
2023-08-30 10:25:18 +02:00
url: "http://192.168.77.106:9000/api/stacks/{{ item }}/stop?endpointId=13"
2023-08-22 10:03:54 +02:00
method: POST
body_format: form-urlencoded
return_content: yes
headers:
Content-Type: "application/json"
X-API-Key: "ptr_DfS2M6Fj2P3fVvYpkhE0KJh2UGCzY47ePaFaLqadsjg="
timeout: 60
register: result
when: inventory_hostname in groups['nas']
2023-08-30 10:25:18 +02:00
loop:
- 130
- 149
2023-08-30 11:06:49 +02:00
#- 140
2023-08-30 11:15:27 +02:00
- 180
2023-08-30 10:49:49 +02:00
2023-08-28 15:34:13 +02:00
- name: Copy archive
2023-08-30 10:49:49 +02:00
ansible.builtin.shell: 'scp /share/Data/{{ arch_name }}-{{ ansible_date_time.date }}.tar.gz admin@192.168.77.246:/tmp/'
2023-08-29 14:02:11 +02:00
when: inventory_hostname in groups['nas']
2023-08-29 14:54:06 +02:00
#- name: Unpack archive
# ansible.builtin.shell: 'tar -xzvf /tmp/dockers-{{ ansible_date_time.date }}.tar.gz -C /'
# become: true
# when: inventory_hostname in groups['raspberry']
- name: Extract
2023-08-29 15:20:13 +02:00
become: yes
2023-08-29 14:54:06 +02:00
ansible.builtin.unarchive:
2023-08-30 10:49:49 +02:00
src: /tmp/{{ arch_name }}-{{ ansible_date_time.date }}.tar.gz
2023-08-29 14:54:06 +02:00
dest: /
2023-08-29 15:11:59 +02:00
remote_src: yes
2023-09-29 08:46:54 +02:00
owner: admin
group: administrators
2023-09-29 09:00:37 +02:00
when: inventory_hostname in groups['raspberry']
2023-09-29 09:02:27 +02:00
- name: fix permissions
file:
path: /share/docker_data/mailu2/
owner: admin
group: administrators
recurse: yes