From d057ad0b6a56110b49796bc2d6a331dd4ce9045f Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Fri, 24 Jul 2020 07:28:06 -0600 Subject: [PATCH] Switch from handlers to tasks Handlers normally don't run until the end of a play execution. Since we are forcing a handler run in the middle of the tasks there is not a good reason to use handlers for this case. Additionally we're not relying on this handler anywhere else. Because of this, let's switch to explicit tasks that check changed results instead of handlers. We've seen issues with trying to use handlers in ansible when not using a linear strategy. Change-Id: I4eb5ece7d5c1d25f5beacd9e21e20ae9f3d45c17 Closes-Bug: #1888853 --- .../roles/tripleo_cellv2/handlers/main.yml | 31 -------- .../tasks/add_internalapi_hosts_entries.yml | 25 +++++- .../handlers/main.yml | 26 ------ .../tasks/main.yml | 18 ++++- .../roles/tripleo_firewall/handlers/main.yml | 79 ------------------- .../roles/tripleo_firewall/tasks/main.yml | 57 ++++++++++++- .../roles/tripleo_kernel/handlers/main.yml | 27 ------- .../roles/tripleo_kernel/tasks/main.yml | 25 ++++-- .../tripleo_module_load/handlers/main.yml | 21 ----- .../roles/tripleo_module_load/tasks/main.yml | 11 ++- .../roles/tripleo_ptp/handlers/main.yml | 27 ------- .../tripleo_ptp/tasks/tripleo_phc2sys.yml | 12 ++- .../roles/tripleo_ptp/tasks/tripleo_ptp.yml | 18 +++-- .../roles/tripleo_timezone/handlers/main.yml | 24 ------ .../roles/tripleo_timezone/tasks/main.yml | 16 +++- tripleo_ansible/roles/tuned/handlers/main.yml | 21 ----- .../roles/tuned/tasks/tuned_install.yml | 13 ++- 17 files changed, 161 insertions(+), 290 deletions(-) delete mode 100644 tripleo_ansible/roles/tripleo_cellv2/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tripleo_container_image_prepare/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tripleo_firewall/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tripleo_kernel/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tripleo_module_load/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tripleo_ptp/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tripleo_timezone/handlers/main.yml delete mode 100644 tripleo_ansible/roles/tuned/handlers/main.yml diff --git a/tripleo_ansible/roles/tripleo_cellv2/handlers/main.yml b/tripleo_ansible/roles/tripleo_cellv2/handlers/main.yml deleted file mode 100644 index 4f68b07d4..000000000 --- a/tripleo_ansible/roles/tripleo_cellv2/handlers/main.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -- name: nova restart podman - become: true - systemd: - name: "{{ item }}" - state: restarted - with_items: - - tripleo_nova_api - - tripleo_nova_conductor - - tripleo_nova_scheduler - when: tripleo_cellv2_containercli == "podman" - -- name: nova restart docker - become: true - command: docker restart nova_api nova_scheduler nova_conductor - when: tripleo_cellv2_containercli == "docker" diff --git a/tripleo_ansible/roles/tripleo_cellv2/tasks/add_internalapi_hosts_entries.yml b/tripleo_ansible/roles/tripleo_cellv2/tasks/add_internalapi_hosts_entries.yml index 99b50425a..a131038c4 100644 --- a/tripleo_ansible/roles/tripleo_cellv2/tasks/add_internalapi_hosts_entries.yml +++ b/tripleo_ansible/roles/tripleo_cellv2/tasks/add_internalapi_hosts_entries.yml @@ -30,9 +30,28 @@ - hostvars[item]['internal_api_hostname'] is defined with_items: "{{ tripleo_cellv2_cellcontroller_group }}" register: hosts_result - notify: - - nova restart podman - - nova restart docker + tags: + - hosts + - create + +- name: Restart nova services + become: true + block: + - name: nova restart podman + systemd: + name: "{{ item }}" + state: restarted + with_items: + - tripleo_nova_api + - tripleo_nova_conductor + - tripleo_nova_scheduler + when: tripleo_cellv2_containercli == "podman" + + - name: nova restart docker + command: docker restart nova_api nova_scheduler nova_conductor + when: tripleo_cellv2_containercli == "docker" + when: + - hosts_result.changed tags: - hosts - create diff --git a/tripleo_ansible/roles/tripleo_container_image_prepare/handlers/main.yml b/tripleo_ansible/roles/tripleo_container_image_prepare/handlers/main.yml deleted file mode 100644 index 42eced777..000000000 --- a/tripleo_ansible/roles/tripleo_container_image_prepare/handlers/main.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -- name: Delete param file - command: "rm -rf '{{ prepare_param.path }}'" - check_mode: false - become: true - -- name: Delete role file - command: "rm -rf '{{ role_data.path }}'" - check_mode: false - become: true diff --git a/tripleo_ansible/roles/tripleo_container_image_prepare/tasks/main.yml b/tripleo_ansible/roles/tripleo_container_image_prepare/tasks/main.yml index 5ed9cfa4a..6c80b9a1c 100644 --- a/tripleo_ansible/roles/tripleo_container_image_prepare/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo_container_image_prepare/tasks/main.yml @@ -25,8 +25,6 @@ suffix: -prepare-param register: prepare_param check_mode: false - notify: - - Delete param file - name: Write ContainerImagePrepare parameter file copy: @@ -39,8 +37,6 @@ suffix: -role-data register: role_data check_mode: false - notify: - - Delete role file - name: Write role data file copy: @@ -61,5 +57,19 @@ when: - (tripleo_container_image_prepare_content | dict2items | length) > 0 - (tripleo_container_image_prepare_roles | length) > 0 + always: + - name: Delete param file + command: "rm -rf '{{ prepare_param.path }}'" + when: + - prepare_param is defined + - prepare_param.changed + check_mode: false + + - name: Delete role file + command: "rm -rf '{{ role_data.path }}'" + when: + - role_data is defined + - role_data.changed + check_mode: false tags: - container_image_prepare diff --git a/tripleo_ansible/roles/tripleo_firewall/handlers/main.yml b/tripleo_ansible/roles/tripleo_firewall/handlers/main.yml deleted file mode 100644 index c6ff3aaff..000000000 --- a/tripleo_ansible/roles/tripleo_firewall/handlers/main.yml +++ /dev/null @@ -1,79 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -- name: Save firewall rules ipv4 - command: /usr/libexec/iptables/iptables.init save - become: true - listen: Save firewall rules - -- name: Save firewall rules ipv6 - command: /usr/libexec/iptables/ip6tables.init save - become: true - listen: Save firewall rules - -- name: Enable iptables service (and do a daemon-reload systemd) - systemd: - daemon_reload: true - enabled: true - name: "{{ item }}" - state: started - loop: - - iptables.service - - ip6tables.service - become: true - listen: Save firewall rules - -- name: Enable tripleo-iptables service (and do a daemon-reload systemd) - systemd: - daemon_reload: true - enabled: true - name: "{{ item }}" - state: started - loop: - - tripleo-iptables.service - - tripleo-ip6tables.service - failed_when: false - become: true - listen: Save firewall rules - -- name: Stop and disable firewalld - systemd: - enabled: false - name: "firewalld.service" - state: stopped - failed_when: false - become: true - listen: Save firewall rules - -- name: Find non-persistent rules - command: egrep -l 'comment.*(neutron-|ironic-inspector)' /etc/sysconfig/iptables* /etc/sysconfig/ip6tables* - failed_when: false - changed_when: false - register: neutron_rules - become: true - listen: Save firewall rules - -- name: Remove non-persistent line(s) - lineinfile: - path: "{{ item }}" - state: absent - regexp: '^((?!.*comment)(?=.*(ironic-inspector|neutron-)))' - when: - - item.find('v=' ~ '^/') == -1 - loop: "{{ neutron_rules.stdout_lines }}" - become: true - listen: Save firewall rules diff --git a/tripleo_ansible/roles/tripleo_firewall/tasks/main.yml b/tripleo_ansible/roles/tripleo_firewall/tasks/main.yml index ed41ab2a0..4890197a7 100644 --- a/tripleo_ansible/roles/tripleo_firewall/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo_firewall/tasks/main.yml @@ -56,5 +56,58 @@ - name: Manage firewall rules tripleo_iptables: tripleo_rules: "{{ firewall_rules_sorted }}" - notify: - - Save firewall rules + register: _iptables_result + +- name: Firewall save block + when: + - _iptables_result.changed + become: true + block: + - name: Save firewall rules ipv4 + command: /usr/libexec/iptables/iptables.init save + + - name: Save firewall rules ipv6 + command: /usr/libexec/iptables/ip6tables.init save + + - name: Enable iptables service (and do a daemon-reload systemd) + systemd: + daemon_reload: true + enabled: true + name: "{{ item }}" + state: started + loop: + - iptables.service + - ip6tables.service + + - name: Enable tripleo-iptables service (and do a daemon-reload systemd) + systemd: + daemon_reload: true + enabled: true + name: "{{ item }}" + state: started + loop: + - tripleo-iptables.service + - tripleo-ip6tables.service + failed_when: false + + - name: Stop and disable firewalld + systemd: + enabled: false + name: "firewalld.service" + state: stopped + failed_when: false + + - name: Find non-persistent rules + command: egrep -l 'comment.*(neutron-|ironic-inspector)' /etc/sysconfig/iptables* /etc/sysconfig/ip6tables* + failed_when: false + changed_when: false + register: neutron_rules + + - name: Remove non-persistent line(s) + lineinfile: + path: "{{ item }}" + state: absent + regexp: '^((?!.*comment)(?=.*(ironic-inspector|neutron-)))' + when: + - item.find('v=' ~ '^/') == -1 + loop: "{{ neutron_rules.stdout_lines }}" diff --git a/tripleo_ansible/roles/tripleo_kernel/handlers/main.yml b/tripleo_ansible/roles/tripleo_kernel/handlers/main.yml deleted file mode 100644 index 4e7788ef9..000000000 --- a/tripleo_ansible/roles/tripleo_kernel/handlers/main.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -- name: Sysctl reload - become: true - systemd: - name: systemd-sysctl.service - state: restarted - -- name: Modules reload - become: true - systemd: - name: systemd-modules-load.service - state: restarted diff --git a/tripleo_ansible/roles/tripleo_kernel/tasks/main.yml b/tripleo_ansible/roles/tripleo_kernel/tasks/main.yml index c0af68dd4..dad3908cd 100644 --- a/tripleo_ansible/roles/tripleo_kernel/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo_kernel/tasks/main.yml @@ -25,7 +25,7 @@ name: "{{ item.key }}" state: "{{ item.opt.state | default('present') }}" loop: "{{ tripleo_kernel_extra_packages | dict2items(key_name='key', value_name='opt') }}" - notify: Modules reload + register: _install_packages_result - name: Remove dracut-config-generic package: @@ -49,10 +49,14 @@ owner: root group: root setype: etc_t - notify: Modules reload + register: _modprobe_result - - name: Run handlers to load new modules - meta: flush_handlers + - name: Modules reload + systemd: + name: systemd-modules-load.service + state: restarted + when: + - _install_packages_result.changed or _modprobe_result.changed - name: Set default sysctl options template: @@ -62,8 +66,7 @@ owner: root group: root setype: etc_t - notify: - - Sysctl reload + register: _default_sysctl_result - name: Set extra sysctl options sysctl: @@ -74,5 +77,11 @@ sysctl_file: "/etc/sysctl.d/99-tripleo.conf" reload: false loop: "{{ tripleo_kernel_sysctl_extra_settings | dict2items(key_name='key', value_name='opt') }}" - notify: - - Sysctl reload + register: _extra_sysctl_result + + - name: Sysctl reload + systemd: + name: systemd-sysctl.service + state: restarted + when: + - _extra_sysctl_result.changed or _default_sysctl_result.changed diff --git a/tripleo_ansible/roles/tripleo_module_load/handlers/main.yml b/tripleo_ansible/roles/tripleo_module_load/handlers/main.yml deleted file mode 100644 index 494b0e37b..000000000 --- a/tripleo_ansible/roles/tripleo_module_load/handlers/main.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -- name: Modules reload - become: true - systemd: - name: systemd-modules-load.service - state: restarted diff --git a/tripleo_ansible/roles/tripleo_module_load/tasks/main.yml b/tripleo_ansible/roles/tripleo_module_load/tasks/main.yml index ce4ca1a40..7d08dfa13 100644 --- a/tripleo_ansible/roles/tripleo_module_load/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo_module_load/tasks/main.yml @@ -43,8 +43,7 @@ loop: "{{ tripleo_modules }}" loop_control: label: "{{ item.name }}" - notify: - - Modules reload + register: _tripleo_modules_add when: - (item.state | default('present')) == 'present' @@ -55,6 +54,7 @@ loop: "{{ tripleo_modules }}" loop_control: label: "{{ item.name }}" + register: _tripleo_modules_remove when: - (item.state | default('present')) == 'absent' @@ -67,3 +67,10 @@ loop: "{{ tripleo_modules }}" loop_control: label: "{{ item.name }}" + + - name: Modules reload + systemd: + name: systemd-modules-load.service + state: restarted + when: + - _tripleo_modules_add.changed or _tripleo_modules_remove.changed diff --git a/tripleo_ansible/roles/tripleo_ptp/handlers/main.yml b/tripleo_ansible/roles/tripleo_ptp/handlers/main.yml deleted file mode 100644 index 3708bc7a4..000000000 --- a/tripleo_ansible/roles/tripleo_ptp/handlers/main.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -- name: Enable and start the ptp service - systemd: - name: ptp4l - state: started - enabled: true - -- name: Enable and start the phc2sys service - systemd: - name: phc2sys - state: restarted - enabled: true diff --git a/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_phc2sys.yml b/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_phc2sys.yml index 35f202cdd..ab8f7ef4f 100644 --- a/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_phc2sys.yml +++ b/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_phc2sys.yml @@ -35,5 +35,13 @@ dest: /etc/sysconfig/phc2sys when: - tripleo_phc_interface - notify: - - Enable and start the phc2sys service + register: _ptp_phc2sys_sysconfig_result + +- name: Enable and start the phc2sys service + become: true + systemd: + name: phc2sys + state: restarted + enabled: true + when: + - _ptp_phc2sys_sysconfig_result.changed diff --git a/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_ptp.yml b/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_ptp.yml index 360225c87..898936e93 100644 --- a/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_ptp.yml +++ b/tripleo_ansible/roles/tripleo_ptp/tasks/tripleo_ptp.yml @@ -19,8 +19,7 @@ package: name: "{{ tripleo_ptp_packages }}" state: present - notify: - - Enable and start the ptp service + register: _ptp_install_result - name: Collect only facts returned by facter setup: @@ -60,13 +59,20 @@ template: src: "ptp4l.conf.j2" dest: /etc/ptp4l.conf - notify: - - Enable and start the ptp service + register: _ptp_config_result - name: Create ptp service config copy: content: |- OPTIONS="-f /etc/ptp4l.conf" dest: /etc/sysconfig/ptp4l - notify: - - Enable and start the ptp service + register: _ptp_sysconfig_result + +- name: Enable and start the ptp service + become: true + systemd: + name: ptp4l + state: restarted + enabled: true + when: + - _ptp_install_result.changed or _ptp_config_result.changed or _ptp_sysconfig_result.changed diff --git a/tripleo_ansible/roles/tripleo_timezone/handlers/main.yml b/tripleo_ansible/roles/tripleo_timezone/handlers/main.yml deleted file mode 100644 index 24b875cb8..000000000 --- a/tripleo_ansible/roles/tripleo_timezone/handlers/main.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -- name: Restart time services - systemd: - name: "{{ item }}" - state: restarted - with_items: - - rsyslog - - crond diff --git a/tripleo_ansible/roles/tripleo_timezone/tasks/main.yml b/tripleo_ansible/roles/tripleo_timezone/tasks/main.yml index c1daa5e54..d9b9fdd52 100644 --- a/tripleo_ansible/roles/tripleo_timezone/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo_timezone/tasks/main.yml @@ -20,8 +20,16 @@ - name: Set timezone timezone: name: "{{ tripleo_timezone }}" - notify: - - Restart time services + register: _timezone_result -- name: Force all notified handlers to run at this point - meta: flush_handlers +- name: Restart time services + systemd: + name: "{{ time_svc }}" + state: restarted + loop_control: + loop_var: time_svc + loop: + - rsyslog + - crond + when: + - _timezone_result.changed diff --git a/tripleo_ansible/roles/tuned/handlers/main.yml b/tripleo_ansible/roles/tuned/handlers/main.yml deleted file mode 100644 index ffbe6cb44..000000000 --- a/tripleo_ansible/roles/tuned/handlers/main.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -# Copyright 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -- name: Restart tuned - systemd: - name: tuned - state: restarted - enabled: true diff --git a/tripleo_ansible/roles/tuned/tasks/tuned_install.yml b/tripleo_ansible/roles/tuned/tasks/tuned_install.yml index a22c9c477..aca854c18 100644 --- a/tripleo_ansible/roles/tuned/tasks/tuned_install.yml +++ b/tripleo_ansible/roles/tuned/tasks/tuned_install.yml @@ -16,10 +16,17 @@ - name: Install tuned + become: true package: name: "{{ tuned_system_packages }}" state: present - notify: Restart tuned + register: _tuned_install_result -- name: Flush handlers - meta: flush_handlers +- name: Restart tuned + become: true + systemd: + name: tuned + state: restarted + enabled: true + when: + - _tuned_install_result.changed