-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrolling_update_zdm_proxy.yml
99 lines (92 loc) · 4.2 KB
/
rolling_update_zdm_proxy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
- name: Install Docker Python module
hosts: proxies
become: yes
tasks:
- name: Ensure Docker Ansible module is installed - Debian/Ubuntu
include_tasks: tasks/install_docker_ansible_module.yml
vars:
- install_packages: false
when: ansible_os_family == "Debian"
- name: Ensure Docker Ansible module is installed - RedHat
include_tasks: tasks/install_docker_ansible_module-centos.yml
vars:
- install_packages: false
when: ansible_os_family == "RedHat" or ansible_os_family == "Rocky"
- name: Create ZDM proxy configuration env file based on the latest configuration
hosts: proxies
vars_files:
- vars/zdm_proxy_container_config.yml
- vars/zdm_proxy_cluster_config.yml
- vars/zdm_proxy_core_config.yml
- vars/zdm_proxy_advanced_config.yml
- vars/zdm_playbook_internal_config.yml
tasks:
- name: Generate configuration file from template for mutable configuration
template:
src: "{{ 'zdm_proxy_mutable_config_env_vars.j2' if zdm_proxy_config_mode == 'env_vars' else 'zdm_proxy_mutable_config_file.j2' }}"
dest: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_config_fragments_dir_name }}/{{ zdm_proxy_mutable_config_fragment_file_name }}"
- name: Merge the immutable and mutable configuration files into a single one
assemble:
src: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_config_fragments_dir_name }}"
dest: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_environment_config_file_name if zdm_proxy_config_mode == 'env_vars' else (zdm_proxy_shared_assets_dir_name + '/' + zdm_proxy_config_file_name) }}"
- name: Configure and restart each ZDM proxy in a rolling fashion
hosts: proxies
serial: 1
become: yes
vars_files:
- vars/zdm_proxy_container_config.yml
- vars/zdm_proxy_advanced_config.yml # needed for the metrics_port variable
- vars/zdm_playbook_internal_config.yml
- vars/zdm_proxy_cluster_config.yml
- vars/zdm_proxy_core_config.yml # this inclusion is for backward compatibility and will be removed in the future
tasks:
- name: Create ZDM proxy container with updated env vars
when: "zdm_proxy_config_mode == 'env_vars'"
docker_container:
name: "{{ zdm_proxy_container_name }}"
image: "{{ zdm_proxy_image }}"
env_file: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_environment_config_file_name }}"
env:
ZDM_ORIGIN_USERNAME: "{{ origin_username | default('') }}"
ZDM_ORIGIN_PASSWORD: "{{ origin_password | default('') }}"
ZDM_TARGET_USERNAME: "{{ target_username | default('') }}"
ZDM_TARGET_PASSWORD: "{{ target_password | default('') }}"
mounts:
- source: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_shared_assets_dir_name }}"
target: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_shared_assets_dir_name }}"
type: bind
network_mode: host
restart_policy: unless-stopped
restart: yes
state: started
vars:
ansible_python_interpreter: python3
- name: Create ZDM proxy container with updated configuration file
when: "zdm_proxy_config_mode == 'conf_file'"
docker_container:
name: "{{ zdm_proxy_container_name }}"
image: "{{ zdm_proxy_image }}"
command:
- "--config={{ zdm_proxy_home_dir }}/{{ zdm_proxy_shared_assets_dir_name }}/{{zdm_proxy_config_file_name}}"
mounts:
- source: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_shared_assets_dir_name }}"
target: "{{ zdm_proxy_home_dir }}/{{ zdm_proxy_shared_assets_dir_name }}"
type: bind
network_mode: host
restart_policy: unless-stopped
restart: yes
state: started
vars:
ansible_python_interpreter: python3
- name: Wait for this ZDM proxy to come up
uri:
url: "http://{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ metrics_port }}/health/readiness"
status_code: 200
register: result
until: result.status == 200
retries: 6
delay: 5
- pause:
prompt: "Pause for {{ pause_between_restarts_in_seconds }} seconds after restarting this ZDM proxy instance"
seconds: "{{ pause_between_restarts_in_seconds }}"