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: I6247f86b26d1e0dac55fa863a19405ff171c82ff
This commit is contained in:
Dmitriy Rabotyagov 2020-09-11 15:10:10 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent e7a5487ff2
commit 533c789316
3 changed files with 9 additions and 6 deletions

View File

@ -66,7 +66,7 @@
when:
- item.condition | default(True)
- item.tmp_f
run_once: true
- _ceilometer_is_first_play_host
- name: Copy common config
config_template:

View File

@ -99,13 +99,11 @@
password: "{{ ceilometer_service_password }}"
role: "{{ ceilometer_role_name }}"
when:
- ceilometer_services['ceilometer-agent-notification']['group'] | intersect(group_names) | length > 0
- inventory_hostname == (groups[(ceilometer_services['ceilometer-agent-notification']['group'] | intersect(group_names))[0]] | intersect(ansible_play_hosts))[0]
- _ceilometer_is_first_play_host
tags:
- ceilometer-config
- import_tasks: mq_setup.yml
run_once: yes
vars:
_oslomsg_rpc_setup_host: "{{ ceilometer_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ ceilometer_oslomsg_rpc_userid }}"
@ -117,11 +115,14 @@
_oslomsg_notify_password: "{{ ceilometer_oslomsg_notify_password }}"
_oslomsg_notify_vhost: "{{ ceilometer_oslomsg_notify_vhost }}"
_oslomsg_notify_transport: "{{ ceilometer_oslomsg_notify_transport }}"
when:
- _ceilometer_is_first_play_host
tags:
- common-mq
- ceilometer-config
- import_tasks: ceilometer_db_setup.yml
when:
- _ceilometer_is_first_play_host
tags:
- ceilometer-config
run_once: true
- ceilometer-config

View File

@ -21,6 +21,8 @@ ceilometer_loadbalancer_v2_meter_definitions_user_content: "{{ lookup('file', ce
ceilometer_osprofiler_event_definitions_user_content: "{{ lookup('file', ceilometer_osprofiler_event_definitions_default_file_path, errors='ignore') }}"
ceilometer_polling_user_content: "{{ lookup('file', ceilometer_polling_default_file_path, errors='ignore') }}"
_ceilometer_is_first_play_host: "{{ (ceilometer_services['ceilometer-agent-notification']['group'] | intersect(group_names) | length > 0) and (inventory_hostname == groups[ceilometer_services['ceilometer-agent-notification']['group'] | intersect(group_names) | first] | intersect(ansible_play_hosts) | first) }}"
_ceilometer_rootwrap_conf_overrides:
DEFAULT:
filters_path: "/etc/ceilometer/rootwrap.d,/usr/share/ceilometer/rootwrap"