Skip to content
This repository was archived by the owner on Jan 1, 2024. It is now read-only.

Commit 6ecf7ad

Browse files
authored
Use playbook variables in tasks that use hostsvars (#266)
Closes #259 Before the patch, some tasks use the `hostsvars` magic variable, but it does not take into account the variables from the playbook. Now the `role_vars` variable has been added in `hostsvars`, in which all role variables are stored, taking into account the playbook and other places where variables are declared.
1 parent b9aabba commit 6ecf7ad

21 files changed

+253
-127
lines changed

defaults/main.yml

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
11
---
22

3-
cartridge_remove_temporary_files: false
4-
5-
cartridge_package_path: null
6-
cartridge_defaults: {}
7-
cartridge_enable_tarantool_repo: true
8-
9-
cartridge_bootstrap_vshard: false
10-
cartridge_app_config: null
11-
cartridge_auth: null
12-
cartridge_failover: null
13-
cartridge_failover_params: null
14-
cartridge_wait_buckets_discovery: true
15-
16-
restarted: null
17-
expelled: false
18-
stateboard: false
19-
cartridge_multiversion: false
3+
# Common variables
204

21-
instance_start_timeout: 60
22-
instance_discover_buckets_timeout: 60
23-
edit_topology_timeout: 60
24-
25-
cartridge_app_install_dir: /usr/share/tarantool
26-
cartridge_app_instances_dir: /usr/share/tarantool
27-
cartridge_conf_dir: /etc/tarantool/conf.d
28-
cartridge_run_dir: /var/run/tarantool
29-
cartridge_data_dir: /var/lib/tarantool
30-
cartridge_memtx_dir_parent: null
31-
cartridge_vinyl_dir_parent: null
32-
cartridge_wal_dir_parent: null
5+
cartridge_app_name: null
6+
cartridge_cluster_cookie: null
7+
cartridge_remove_temporary_files: false
338

34-
cartridge_app_user: tarantool
35-
cartridge_app_group: tarantool
9+
# Role scenario configuration
3610

37-
cartridge_custom_steps: []
38-
cartridge_custom_steps_dir: null
3911
cartridge_scenario: null
12+
cartridge_custom_steps_dir: null
13+
cartridge_custom_steps: []
4014

4115
cartridge_scenario_name: 'default'
4216
cartridge_custom_scenarios: {}
@@ -76,22 +50,78 @@ cartridge_role_scenarios:
7650
- configure_failover
7751
- cleanup
7852

53+
# Application package configuration
54+
55+
cartridge_package_path: null
56+
cartridge_enable_tarantool_repo: true
57+
58+
# TGZ specific configuration
59+
60+
cartridge_multiversion: false
61+
62+
cartridge_install_tarantool_for_tgz: true
63+
64+
cartridge_app_user: tarantool
65+
cartridge_app_group: tarantool
66+
67+
cartridge_data_dir: /var/lib/tarantool
68+
cartridge_memtx_dir_parent: null
69+
cartridge_vinyl_dir_parent: null
70+
cartridge_wal_dir_parent: null
71+
cartridge_run_dir: /var/run/tarantool
72+
cartridge_conf_dir: /etc/tarantool/conf.d
73+
cartridge_app_install_dir: /usr/share/tarantool
74+
cartridge_app_instances_dir: /usr/share/tarantool
75+
7976
cartridge_configure_systemd_unit_files: true
8077
cartridge_systemd_dir: /etc/systemd/system
8178

8279
cartridge_configure_tmpfiles: true
8380
cartridge_tmpfiles_dir: /usr/lib/tmpfiles.d/
8481

85-
cartridge_install_tarantool_for_tgz: true
86-
8782
cartridge_keep_num_latest_dists: 2
8883

89-
# Facts initialized in 'main.yml' (for correct 'tasks_from' option usage)
90-
temporary_files: []
84+
# Instances configuration
85+
86+
cartridge_defaults: {}
87+
config: null
88+
zone: null
89+
90+
restarted: null
91+
expelled: false
92+
stateboard: false
93+
94+
cartridge_wait_buckets_discovery: true
95+
instance_start_timeout: 60
96+
instance_discover_buckets_timeout: 60
97+
98+
# Replicasets configuration
99+
100+
replicaset_alias: null
101+
failover_priority: null
102+
roles: null
103+
all_rw: null
104+
vshard_group: null
105+
weight: null
106+
edit_topology_timeout: 60
107+
108+
## Cluster configuration
109+
110+
cartridge_bootstrap_vshard: false
111+
cartridge_app_config: null
112+
cartridge_auth: null
113+
cartridge_failover: null
114+
cartridge_failover_params: null
115+
116+
# Internal role facts that can be set by the user
117+
118+
cartridge_delivered_package_path: null
119+
cartridge_control_instance: null
120+
121+
# Cross-step facts (for correct 'tasks_from' option usage)
122+
91123
delivered_package_path: null
92-
package_info: null
93-
systemd_units_info: null
124+
control_instance: null
125+
temporary_files: []
94126
needs_restart: null
95127
non_expelled_instance: null
96-
control_instance: null
97-
dists_dirs_to_remove: null

doc/scenario.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ remove `connect_to_membership` step from scenario:
208208

209209
If you are using multiversion, then most likely you are upgrading to the new version of the package gradually:
210210
first storages, then routers, etc. To do this, the same scenario to update the package version is used several times.
211-
Let's remove duplication by declaring a custom script and then using it!
211+
Let's remove duplication by declaring a custom scenario and then using it!
212212

213213
Firstly you should to define custom scenarios in hosts file:
214214

@@ -282,6 +282,7 @@ Some of useful facts are established during preparation, so you can use them at
282282
- `scenario_steps` - description of scenario steps. Each step is a dictionary with fields:
283283
- `name` - name of step;
284284
- `path` - path to YAML file of step;
285+
- `role_vars` - dictionary with all role variables.
285286

286287
## Role Steps Description
287288

doc/variables.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ vshard bootstrapping, and failover.
88
* `cartridge_app_name` (`string`): application name, required;
99
* `cartridge_cluster_cookie` (`string`, required): cluster cookie for all
1010
cluster instances;
11-
* `cartridge_multiversion` (`boolean`, default: `false`): use multiversion
12-
approach for TGZ package.
1311
* `cartridge_remove_temporary_files` (`boolean`, optional, default: `false`):
1412
indicates if temporary files should be removed
1513
(more details in description of [`cleanup` step API](/doc/scenario.md#cleanup));
@@ -19,11 +17,13 @@ vshard bootstrapping, and failover.
1917
For more details see [scenario documentation](/doc/scenario.md).
2018

2119
* `cartridge_scenario` (`list-of-strings`): list of steps to be launched
22-
(see [change scenario](/README.md#using-scenario) for more details)
20+
(see [change scenario](/README.md#using-scenario) for more details);
2321
* `cartridge_custom_steps_dir` (`string`, default: `null`): path to directory
24-
containing YAML files of custom steps (see [change scenario](/README.md#using-scenario) for more details)
22+
containing YAML files of custom steps (see [change scenario](/README.md#using-scenario) for more details);
2523
* `cartridge_custom_steps` (`list-of-dicts`, default: `[]`): list of custom steps
26-
(see [change scenario](/README.md#using-scenario) for more details)
24+
(see [change scenario](/README.md#using-scenario) for more details);
25+
* `cartridge_scenario_name` (`string`, default: `default`): name of scenario to be launched;
26+
* `cartridge_custom_scenarios` (`dict-of-lists`, default: `{}`): dictionary of custom scenarios;
2727

2828
## Application package configuration
2929

@@ -69,6 +69,9 @@ For more details see [scenario documentation](/doc/scenario.md).
6969
* `cartridge_tmpfiles_dir` (`string`, default: `/usr/lib/tmpfiles.d/`): a directory where
7070
tmpfile configuration should be placed;
7171

72+
* `cartridge_keep_num_latest_dists` (`number`, default: 2): the number of application
73+
versions that should be kept during distribution rotation;
74+
7275
## Instances configuration
7376

7477
* `config` (`dict`, required): [instance configuration](/doc/instances.md);
@@ -94,6 +97,7 @@ For more details see [scenario documentation](/doc/scenario.md).
9497
* `failover_priority` (`list-of-strings`): failover priority;
9598
* `roles` (`list-of-strings`, required if `replicaset_alias` specified): roles to be enabled on the replicaset;
9699
* `all_rw` (`boolean`): indicates that that all servers in the replicaset should be read-write;
100+
* `vshard_group` (`string`): name of vshard group the replicaset belongs to;
97101
* `weight` (`number`): vshard replicaset weight (matters only if `vshard-storage` role is enabled);
98102
* `edit_topology_timeout` (`number`, default: `60`): time in seconds to wait until a cluster become
99103
healthy after editing topology;

library/cartridge_connect_to_membership.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def connect_to_membership(params):
3232
changed = False
3333

3434
for instance_name, instance_vars in hostvars.items():
35+
if 'role_vars' in instance_vars:
36+
instance_vars = instance_vars['role_vars']
37+
3538
if helpers.is_expelled(instance_vars) or helpers.is_stateboard(instance_vars):
3639
continue
3740

library/cartridge_edit_topology.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def get_cluster_instances(control_console):
118118

119119
def get_configured_replicasets(hostvars, play_hosts):
120120
replicasets = {}
121-
for instance_name, instance_vars in hostvars.items():
122-
if instance_name not in play_hosts:
123-
continue
121+
122+
for instance_name in play_hosts:
123+
instance_vars = hostvars[instance_name]['role_vars']
124124

125125
if helpers.is_expelled(instance_vars) or helpers.is_stateboard(instance_vars):
126126
continue
@@ -148,7 +148,8 @@ def get_instances_to_configure(hostvars, play_hosts):
148148
instances = {}
149149

150150
for instance_name in play_hosts:
151-
instance_vars = hostvars[instance_name]
151+
instance_vars = hostvars[instance_name]['role_vars']
152+
152153
if helpers.is_stateboard(instance_vars):
153154
continue
154155

library/cartridge_get_control_instance.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def get_control_instance(params):
110110

111111
if not control_instance_candidates:
112112
for instance_name in play_hosts:
113-
instance_vars = hostvars[instance_name]
113+
instance_vars = hostvars[instance_name]['role_vars']
114+
114115
if helpers.is_expelled(instance_vars) or helpers.is_stateboard(instance_vars):
115116
continue
116117

@@ -122,6 +123,8 @@ def get_control_instance(params):
122123
return helpers.ModuleRes(failed=True, msg=errmsg)
123124

124125
advertise_uris = [
126+
hostvars[instance_name]['role_vars']['config']['advertise_uri']
127+
if 'role_vars' in hostvars[instance_name] else
125128
hostvars[instance_name]['config']['advertise_uri']
126129
for instance_name in control_instance_candidates
127130
]
@@ -137,6 +140,8 @@ def get_control_instance(params):
137140
# instance_vars['instance_info'], but if control instance is not
138141
# in play_hosts, instance_info isn't computed for it
139142
instance_vars = hostvars[control_instance_name]
143+
if 'role_vars' in instance_vars:
144+
instance_vars = instance_vars['role_vars']
140145
run_dir = instance_vars.get('cartridge_run_dir', helpers.DEFAULT_RUN_DIR)
141146
control_instance_console_sock = helpers.get_instance_console_sock(
142147
run_dir, app_name, control_instance_name,

library/cartridge_get_not_expelled_instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_one_not_expelled_instance(params):
2020
not_expelled_instance_name = None
2121

2222
for instance_name in play_hosts:
23-
instance_vars = hostvars[instance_name]
23+
instance_vars = hostvars[instance_name]['role_vars']
2424
if helpers.is_expelled(instance_vars) or helpers.is_stateboard(instance_vars):
2525
continue
2626

library/cartridge_get_single_instances_for_each_machine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_one_not_expelled_instance_for_machine(params):
3030
for instance_name in play_hosts:
3131
instance_vars = hostvars[instance_name]
3232

33-
if helpers.is_expelled(instance_vars):
33+
if helpers.is_expelled(instance_vars['role_vars']):
3434
continue
3535

3636
machine_hostname = get_machine_hostname(instance_vars, instance_name)

0 commit comments

Comments
 (0)