From 7f24f8d34afa5c28a4794add18458bd451747ba3 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 11 Sep 2020 15:24:14 +0300 Subject: [PATCH] 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 --- tasks/cinder_post_install.yml | 2 +- tasks/main.yml | 17 +++++------------ vars/main.yml | 2 ++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tasks/cinder_post_install.yml b/tasks/cinder_post_install.yml index 2061ed80..dc510714 100644 --- a/tasks/cinder_post_install.yml +++ b/tasks/cinder_post_install.yml @@ -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: diff --git a/tasks/main.yml b/tasks/main.yml index 8088430d..a19c4ac3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/vars/main.yml b/vars/main.yml index b4581149..f8f23919 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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"