From c4d5649b11912637c8ca4753358747fc1b695d3e Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Mon, 14 Sep 2020 16:32:10 +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: Ic7277f4d3c6697a5be2fa86e07f8b19f0c5db069 --- handlers/main.yml | 3 +-- tasks/main.yml | 9 +++------ tasks/neutron_db_setup.yml | 4 ++-- tasks/neutron_post_install.yml | 2 +- vars/main.yml | 2 ++ 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index d4cdc99b..a37e5b90 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -56,8 +56,7 @@ delegate_to: "{{ groups[neutron_services['neutron-server']['group']][0] }}" when: - "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool" - - "neutron_services['neutron-server']['group'] in group_names" - - "inventory_hostname == ((groups[neutron_services['neutron-server']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - "_neutron_is_first_play_host" listen: - "Restart neutron services" - "venv changed" diff --git a/tasks/main.yml b/tasks/main.yml index 596ab330..4e730658 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -34,8 +34,7 @@ - import_tasks: db_setup.yml when: - - "neutron_services['neutron-server']['group'] in group_names" - - "inventory_hostname == ((groups[neutron_services['neutron-server']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - "_neutron_is_first_play_host" vars: _oslodb_setup_host: "{{ neutron_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ neutron_db_setup_python_interpreter }}" @@ -52,8 +51,7 @@ - import_tasks: mq_setup.yml when: - - "neutron_services['neutron-server']['group'] in group_names" - - "inventory_hostname == ((groups[neutron_services['neutron-server']['group']]| intersect(ansible_play_hosts)) | list)[0]" + - "_neutron_is_first_play_host" vars: _oslomsg_rpc_setup_host: "{{ neutron_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ neutron_oslomsg_rpc_userid }}" @@ -208,8 +206,7 @@ type: "{{ neutron_service_type }}" description: "{{ neutron_service_description }}" when: - - "neutron_services['neutron-server']['group'] in group_names" - - "inventory_hostname == ((groups[neutron_services['neutron-server']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - "_neutron_is_first_play_host" tags: - neutron-config diff --git a/tasks/neutron_db_setup.yml b/tasks/neutron_db_setup.yml index 0f7d8dde..2ca65cc4 100644 --- a/tasks/neutron_db_setup.yml +++ b/tasks/neutron_db_setup.yml @@ -19,7 +19,7 @@ become_user: "{{ neutron_system_user_name }}" when: - "ansible_local['openstack_ansible']['neutron']['need_db_expand'] | bool" - - "inventory_hostname == ((groups[neutron_services['neutron-server']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - "_neutron_is_first_play_host" - name: Disable the db expand fact ini_file: @@ -35,7 +35,7 @@ become: yes become_user: "{{ neutron_system_user_name }}" when: - - "inventory_hostname == ((groups[neutron_services['neutron-server']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - "_neutron_is_first_play_host" changed_when: false register: _offline_migrations_check failed_when: diff --git a/tasks/neutron_post_install.yml b/tasks/neutron_post_install.yml index ff8bdc07..ff457ff6 100644 --- a/tasks/neutron_post_install.yml +++ b/tasks/neutron_post_install.yml @@ -100,7 +100,7 @@ flat: yes changed_when: false with_items: "{{ neutron_core_files }}" - run_once: true + when: _neutron_is_first_play_host - name: Copy common neutron config config_template: diff --git a/vars/main.yml b/vars/main.yml index 26b9ffcc..47bd1ae6 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. +_neutron_is_first_play_host: "{{ (neutron_services['neutron-server']['group'] in group_names and inventory_hostname == (groups[neutron_services['neutron-server']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" + ### ### Open vSwitch ###