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
This commit is contained in:
Dmitriy Rabotyagov 2020-09-14 16:32:10 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent 61a6ac9fba
commit c4d5649b11
5 changed files with 9 additions and 11 deletions

View File

@ -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"

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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
###