commit 25a826e6a669243cec8d7e9f37b11fce79c13b20 Author: Dmitriy Rabotyagov Date: Fri Sep 25 17:50:13 2020 +0300 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: I5bdf7a83d7a5809887f4a445619d87bc7e14b40b diff --git a/tasks/main.yml b/tasks/main.yml index daa26f3..6aee261 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -34,7 +34,7 @@ - import_tasks: db_setup.yml when: - - inventory_hostname == groups['panko_all'][0] + - _panko_is_first_play_host vars: _oslodb_setup_host: "{{ panko_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ panko_db_setup_python_interpreter }}" @@ -94,7 +94,7 @@ - systemd-service - import_tasks: panko_db_sync.yml - when: inventory_hostname == groups['panko_all'][0] + when: _panko_is_first_play_host tags: - panko-config @@ -134,6 +134,6 @@ - name: "{{ panko_service_name }}" type: "{{ panko_service_type }}" description: "{{ panko_service_description }}" - when: inventory_hostname == groups['panko_api'][0] + when: _panko_is_first_play_host tags: - panko-config diff --git a/tasks/panko_post_install.yml b/tasks/panko_post_install.yml index 0d639f6..fda67f4 100644 --- a/tasks/panko_post_install.yml +++ b/tasks/panko_post_install.yml @@ -64,5 +64,5 @@ specialtime: "{{ panko_expirer_job_time }}" job: "{{ panko_bin }}/panko-expirer" when: - - inventory_hostname == groups['panko_all'][0] + - _panko_is_first_play_host - panko_event_time_to_live > 0 diff --git a/vars/main.yml b/vars/main.yml index 756b8af..61fdadf 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. +_panko_is_first_play_host: "{{ (panko_services['panko-api']['group'] in group_names and inventory_hostname == (groups[panko_services['panko-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" + filtered_panko_services: |- {% set services = [] %} {% for name, service in panko_services.items() %}