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
This commit is contained in:
Alex Schultz 2020-07-24 07:28:06 -06:00
parent 1ea0d7c8d2
commit d057ad0b6a
17 changed files with 161 additions and 290 deletions

View File

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

View File

@ -30,9 +30,28 @@
- hostvars[item]['internal_api_hostname'] is defined - hostvars[item]['internal_api_hostname'] is defined
with_items: "{{ tripleo_cellv2_cellcontroller_group }}" with_items: "{{ tripleo_cellv2_cellcontroller_group }}"
register: hosts_result register: hosts_result
notify: tags:
- nova restart podman - hosts
- nova restart docker - 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: tags:
- hosts - hosts
- create - create

View File

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

View File

@ -25,8 +25,6 @@
suffix: -prepare-param suffix: -prepare-param
register: prepare_param register: prepare_param
check_mode: false check_mode: false
notify:
- Delete param file
- name: Write ContainerImagePrepare parameter file - name: Write ContainerImagePrepare parameter file
copy: copy:
@ -39,8 +37,6 @@
suffix: -role-data suffix: -role-data
register: role_data register: role_data
check_mode: false check_mode: false
notify:
- Delete role file
- name: Write role data file - name: Write role data file
copy: copy:
@ -61,5 +57,19 @@
when: when:
- (tripleo_container_image_prepare_content | dict2items | length) > 0 - (tripleo_container_image_prepare_content | dict2items | length) > 0
- (tripleo_container_image_prepare_roles | 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: tags:
- container_image_prepare - container_image_prepare

View File

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

View File

@ -56,5 +56,58 @@
- name: Manage firewall rules - name: Manage firewall rules
tripleo_iptables: tripleo_iptables:
tripleo_rules: "{{ firewall_rules_sorted }}" tripleo_rules: "{{ firewall_rules_sorted }}"
notify: register: _iptables_result
- Save firewall rules
- 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 }}"

View File

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

View File

@ -25,7 +25,7 @@
name: "{{ item.key }}" name: "{{ item.key }}"
state: "{{ item.opt.state | default('present') }}" state: "{{ item.opt.state | default('present') }}"
loop: "{{ tripleo_kernel_extra_packages | dict2items(key_name='key', value_name='opt') }}" loop: "{{ tripleo_kernel_extra_packages | dict2items(key_name='key', value_name='opt') }}"
notify: Modules reload register: _install_packages_result
- name: Remove dracut-config-generic - name: Remove dracut-config-generic
package: package:
@ -49,10 +49,14 @@
owner: root owner: root
group: root group: root
setype: etc_t setype: etc_t
notify: Modules reload register: _modprobe_result
- name: Run handlers to load new modules - name: Modules reload
meta: flush_handlers systemd:
name: systemd-modules-load.service
state: restarted
when:
- _install_packages_result.changed or _modprobe_result.changed
- name: Set default sysctl options - name: Set default sysctl options
template: template:
@ -62,8 +66,7 @@
owner: root owner: root
group: root group: root
setype: etc_t setype: etc_t
notify: register: _default_sysctl_result
- Sysctl reload
- name: Set extra sysctl options - name: Set extra sysctl options
sysctl: sysctl:
@ -74,5 +77,11 @@
sysctl_file: "/etc/sysctl.d/99-tripleo.conf" sysctl_file: "/etc/sysctl.d/99-tripleo.conf"
reload: false reload: false
loop: "{{ tripleo_kernel_sysctl_extra_settings | dict2items(key_name='key', value_name='opt') }}" loop: "{{ tripleo_kernel_sysctl_extra_settings | dict2items(key_name='key', value_name='opt') }}"
notify: register: _extra_sysctl_result
- Sysctl reload
- name: Sysctl reload
systemd:
name: systemd-sysctl.service
state: restarted
when:
- _extra_sysctl_result.changed or _default_sysctl_result.changed

View File

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

View File

@ -43,8 +43,7 @@
loop: "{{ tripleo_modules }}" loop: "{{ tripleo_modules }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
notify: register: _tripleo_modules_add
- Modules reload
when: when:
- (item.state | default('present')) == 'present' - (item.state | default('present')) == 'present'
@ -55,6 +54,7 @@
loop: "{{ tripleo_modules }}" loop: "{{ tripleo_modules }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
register: _tripleo_modules_remove
when: when:
- (item.state | default('present')) == 'absent' - (item.state | default('present')) == 'absent'
@ -67,3 +67,10 @@
loop: "{{ tripleo_modules }}" loop: "{{ tripleo_modules }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
- name: Modules reload
systemd:
name: systemd-modules-load.service
state: restarted
when:
- _tripleo_modules_add.changed or _tripleo_modules_remove.changed

View File

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

View File

@ -35,5 +35,13 @@
dest: /etc/sysconfig/phc2sys dest: /etc/sysconfig/phc2sys
when: when:
- tripleo_phc_interface - tripleo_phc_interface
notify: register: _ptp_phc2sys_sysconfig_result
- Enable and start the phc2sys service
- name: Enable and start the phc2sys service
become: true
systemd:
name: phc2sys
state: restarted
enabled: true
when:
- _ptp_phc2sys_sysconfig_result.changed

View File

@ -19,8 +19,7 @@
package: package:
name: "{{ tripleo_ptp_packages }}" name: "{{ tripleo_ptp_packages }}"
state: present state: present
notify: register: _ptp_install_result
- Enable and start the ptp service
- name: Collect only facts returned by facter - name: Collect only facts returned by facter
setup: setup:
@ -60,13 +59,20 @@
template: template:
src: "ptp4l.conf.j2" src: "ptp4l.conf.j2"
dest: /etc/ptp4l.conf dest: /etc/ptp4l.conf
notify: register: _ptp_config_result
- Enable and start the ptp service
- name: Create ptp service config - name: Create ptp service config
copy: copy:
content: |- content: |-
OPTIONS="-f /etc/ptp4l.conf" OPTIONS="-f /etc/ptp4l.conf"
dest: /etc/sysconfig/ptp4l dest: /etc/sysconfig/ptp4l
notify: register: _ptp_sysconfig_result
- Enable and start the ptp service
- 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

View File

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

View File

@ -20,8 +20,16 @@
- name: Set timezone - name: Set timezone
timezone: timezone:
name: "{{ tripleo_timezone }}" name: "{{ tripleo_timezone }}"
notify: register: _timezone_result
- Restart time services
- name: Force all notified handlers to run at this point - name: Restart time services
meta: flush_handlers systemd:
name: "{{ time_svc }}"
state: restarted
loop_control:
loop_var: time_svc
loop:
- rsyslog
- crond
when:
- _timezone_result.changed

View File

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

View File

@ -16,10 +16,17 @@
- name: Install tuned - name: Install tuned
become: true
package: package:
name: "{{ tuned_system_packages }}" name: "{{ tuned_system_packages }}"
state: present state: present
notify: Restart tuned register: _tuned_install_result
- name: Flush handlers - name: Restart tuned
meta: flush_handlers become: true
systemd:
name: tuned
state: restarted
enabled: true
when:
- _tuned_install_result.changed