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.

Depends-On: https://review.opendev.org/758953
Change-Id: Iab3194322e133282fcb71830f2b94e1279106ebd
This commit is contained in:
Dmitriy Rabotyagov 2020-10-06 18:22:17 +03:00 committed by Dmitriy Rabotyagov
parent 5ba9a1c6e8
commit 67733c8f0c
4 changed files with 9 additions and 10 deletions

View File

@ -25,5 +25,4 @@
become: yes become: yes
changed_when: false changed_when: false
when: when:
- ironic_services['ironic-inspector']['group'] in group_names - _ironic_inspector_is_first_play_host
- inventory_hostname == groups[ironic_services['ironic-inspector']['group']][0]

View File

@ -25,7 +25,7 @@
OS_ENDPOINT_TYPE: internalURL OS_ENDPOINT_TYPE: internalURL
when: when:
- not ironic_enable_web_server_for_images | bool - not ironic_enable_web_server_for_images | bool
- inventory_hostname == groups['ironic_all'][0] - _ironic_api_is_first_play_host
- not ironic_standalone | bool - not ironic_standalone | bool
tags: tags:
- always - always

View File

@ -26,8 +26,7 @@
- import_tasks: db_setup.yml - import_tasks: db_setup.yml
when: when:
- "ironic_services['ironic-api']['group'] in group_names" - _ironic_api_is_first_play_host
- "inventory_hostname == ((groups[ironic_services['ironic-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
vars: vars:
_oslodb_setup_host: "{{ ironic_db_setup_host }}" _oslodb_setup_host: "{{ ironic_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ ironic_db_setup_python_interpreter }}" _oslodb_ansible_python_interpreter: "{{ ironic_db_setup_python_interpreter }}"
@ -44,8 +43,7 @@
- import_tasks: db_setup.yml - import_tasks: db_setup.yml
when: when:
- "ironic_services['ironic-inspector']['group'] in group_names" - _ironic_inspector_is_first_play_host
- "inventory_hostname == ((groups[ironic_services['ironic-inspector']['group']]| intersect(ansible_play_hosts)) | list)[0]"
vars: vars:
_oslodb_setup_host: "{{ ironic_inspector_db_setup_host }}" _oslodb_setup_host: "{{ ironic_inspector_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ ironic_inspector_db_setup_python_interpreter }}" _oslodb_ansible_python_interpreter: "{{ ironic_inspector_db_setup_python_interpreter }}"
@ -62,8 +60,7 @@
- import_tasks: mq_setup.yml - import_tasks: mq_setup.yml
when: when:
- "ironic_services['ironic-api']['group'] in group_names" - _ironic_api_is_first_play_host
- "inventory_hostname == ((groups[ironic_services['ironic-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
vars: vars:
_oslomsg_rpc_setup_host: "{{ ironic_oslomsg_rpc_setup_host }}" _oslomsg_rpc_setup_host: "{{ ironic_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ ironic_oslomsg_rpc_userid }}" _oslomsg_rpc_userid: "{{ ironic_oslomsg_rpc_userid }}"
@ -153,7 +150,7 @@
_service_users: "{{ ironic_service_user_list }}" _service_users: "{{ ironic_service_user_list }}"
_service_endpoints: "{{ ironic_service_endpoint_list }}" _service_endpoints: "{{ ironic_service_endpoint_list }}"
_service_catalog: "{{ ironic_service_catalog_list }}" _service_catalog: "{{ ironic_service_catalog_list }}"
when: (inventory_hostname == groups['ironic_api'][0] or inventory_hostname == groups['ironic_inspector'][0]) when: (_ironic_api_is_first_play_host or _ironic_inspector_is_first_play_host)
tags: tags:
- ironic-config - ironic-config

View File

@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
_ironic_api_is_first_play_host: "{{ (ironic_services['ironic-api']['group'] in group_names and inventory_hostname == (groups[ironic_services['ironic-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}"
_ironic_inspector_is_first_play_host: "{{ (ironic_services['ironic-inspector']['group'] in group_names and inventory_hostname == (groups[ironic_services['ironic-inspector']['group']] | intersect(ansible_play_hosts)) | first) | bool }}"
# This special list brings together all of the package installations into one # This special list brings together all of the package installations into one
# task to save time. # task to save time.