Define condition for the first play host one time

We use the same condition, which defines against what host some "service"
tasks should run against, several times. It's hard to keep it the same
across the role and ansible spending additional resources to evaluate
it each time, so it's simpler and better for the maintenance to set
a boolean variable which will say for all tasks, that we want to run
only against signle host, if they should run or not now.

Change-Id: Ibdb078d39b3189c844aed14aa1ae74cb2ce97600
This commit is contained in:
Dmitriy Rabotyagov 2020-09-11 15:24:14 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent 87bbbe869a
commit 7f24f8d34a
3 changed files with 8 additions and 13 deletions

View File

@ -84,7 +84,7 @@
flat: yes
changed_when: false
with_items: "{{ cinder_core_files }}"
run_once: true
when: _cinder_is_first_play_host
- name: Copy common config
config_template:

View File

@ -42,8 +42,7 @@
- import_tasks: db_setup.yml
when:
- "cinder_services['cinder-api']['group'] in group_names"
- "inventory_hostname == ((groups[cinder_services['cinder-api']['group']] | intersect(ansible_play_hosts)) | list)[0]"
- _cinder_is_first_play_host
vars:
_oslodb_setup_host: "{{ cinder_db_setup_host }}"
_oslodb_databases:
@ -57,8 +56,7 @@
- import_tasks: mq_setup.yml
when:
- "cinder_services['cinder-api']['group'] in group_names"
- "inventory_hostname == ((groups[cinder_services['cinder-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- _cinder_is_first_play_host
vars:
_oslomsg_rpc_setup_host: "{{ cinder_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ cinder_oslomsg_rpc_userid }}"
@ -129,9 +127,7 @@
- import_tasks: cinder_db_sync.yml
when:
- "groups['cinder_api'] | length > 0"
- "cinder_services['cinder-api']['group'] in group_names"
- "inventory_hostname == ((groups['cinder_api'] | intersect(ansible_play_hosts)) | list)[0]"
- _cinder_is_first_play_host
tags:
- cinder-config
@ -160,9 +156,7 @@
password: "{{ cinder_service_password }}"
role: "{{ cinder_service_role_name }}"
when:
- "groups['cinder_api'] | length > 0"
- "cinder_services['cinder-api']['group'] in group_names"
- "inventory_hostname == ((groups['cinder_api'] | intersect(ansible_play_hosts)) | list)[0]"
- "_cinder_is_first_play_host"
tags:
- cinder-config
@ -200,7 +194,6 @@
- import_tasks: cinder_backends.yml
when:
- "groups[cinder_services['cinder-volume']['group']] | length > 0"
- "cinder_services['cinder-api']['group'] in group_names"
- "inventory_hostname == ((groups[cinder_services['cinder-api']['group']] | intersect(ansible_play_hosts)) | list)[-1]"
- "_cinder_is_first_play_host"
tags:
- cinder-config

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
_cinder_is_first_play_host: "{{ (cinder_services['cinder-api']['group'] in group_names and inventory_hostname == (groups[cinder_services['cinder-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}"
_cinder_rootwrap_conf_overrides:
DEFAULT:
filters_path: "/etc/cinder/rootwrap.d,/usr/share/cinder/rootwrap"