tripleo_container_manage: continue to reduce tasks
1) shutdown: include tasks without a block. this should remove the stat and include task; to only have one task that include the shutdown playbook if needed. 2) Remove containers_changed tasks. This is not useful to restart a container just because its podman_container resource changed. when podman_container module applies a change to the container, this one is already restarted. 3) Remove all_containers_commands tasks, there aren't needed. Ansible output already provides the commands that are run via the container_status module. Change-Id: Ic625bc5dd7bbd964d36eab0a3f81eca31c533716
This commit is contained in:
parent
c9cab3399b
commit
ca8fae62e4
|
@ -57,11 +57,6 @@ options:
|
||||||
description:
|
description:
|
||||||
- Whether or not we cleanup the old healthchecks with SystemD.
|
- Whether or not we cleanup the old healthchecks with SystemD.
|
||||||
type: boolean
|
type: boolean
|
||||||
restart_containers:
|
|
||||||
description:
|
|
||||||
- List of container names to be restarted
|
|
||||||
default: []
|
|
||||||
type: list
|
|
||||||
debug:
|
debug:
|
||||||
default: false
|
default: false
|
||||||
description:
|
description:
|
||||||
|
@ -324,24 +319,8 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
container_config = args['container_config']
|
container_config = args['container_config']
|
||||||
systemd_healthchecks = args['systemd_healthchecks']
|
systemd_healthchecks = args['systemd_healthchecks']
|
||||||
restart_containers = args['restart_containers']
|
|
||||||
self.debug = args['debug']
|
self.debug = args['debug']
|
||||||
|
|
||||||
extra_restarts = []
|
|
||||||
for c in restart_containers:
|
|
||||||
s_path = os.path.join('/etc/systemd/system',
|
|
||||||
'tripleo_{}.service'.format(c))
|
|
||||||
service_stat = self._execute_module(
|
|
||||||
module_name='stat',
|
|
||||||
module_args=dict(path=s_path),
|
|
||||||
task_vars=task_vars
|
|
||||||
)
|
|
||||||
if service_stat.get('stat', {}).get('exists', False):
|
|
||||||
if self.debug:
|
|
||||||
DISPLAY.display('This container will be '
|
|
||||||
'restarted: {}'.format(c))
|
|
||||||
extra_restarts.append(c)
|
|
||||||
|
|
||||||
container_names = []
|
container_names = []
|
||||||
for container in container_config:
|
for container in container_config:
|
||||||
for name, config in container.items():
|
for name, config in container.items():
|
||||||
|
@ -355,8 +334,7 @@ class ActionModule(ActionBase):
|
||||||
changed_services = self._create_units(container_config, task_vars)
|
changed_services = self._create_units(container_config, task_vars)
|
||||||
if len(changed_services) > 0:
|
if len(changed_services) > 0:
|
||||||
self._systemd_reload(task_vars)
|
self._systemd_reload(task_vars)
|
||||||
service_names = set(changed_services + extra_restarts)
|
self._restart_services(changed_services, task_vars)
|
||||||
self._restart_services(service_names, task_vars)
|
|
||||||
|
|
||||||
result['changed'] = self.changed
|
result['changed'] = self.changed
|
||||||
result['restarted'] = self.restarted
|
result['restarted'] = self.restarted
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
container_systemd:
|
container_systemd:
|
||||||
container_config: "{{ container_config }}"
|
container_config: "{{ container_config }}"
|
||||||
debug: "{{ tripleo_container_manage_debug | bool }}"
|
debug: "{{ tripleo_container_manage_debug | bool }}"
|
||||||
restart_containers: "{{ containers_changed | default([]) }}"
|
|
||||||
systemd_healthchecks: "{{ (not tripleo_container_manage_healthcheck_disabled | bool) }}"
|
systemd_healthchecks: "{{ (not tripleo_container_manage_healthcheck_disabled | bool) }}"
|
||||||
vars:
|
vars:
|
||||||
container_config: "{{ all_containers_hash | dict_to_list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}"
|
container_config: "{{ all_containers_hash | dict_to_list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}"
|
||||||
|
|
|
@ -55,18 +55,9 @@
|
||||||
all_containers_hash: "{{ container_config_data.configs }}"
|
all_containers_hash: "{{ container_config_data.configs }}"
|
||||||
|
|
||||||
- name: "Manage systemd shutdown files"
|
- name: "Manage systemd shutdown files"
|
||||||
become: true
|
include_tasks: shutdown.yml
|
||||||
when:
|
when:
|
||||||
- tripleo_container_manage_systemd_order
|
- tripleo_container_manage_systemd_order|bool
|
||||||
block:
|
|
||||||
- name: Check if /usr/lib/systemd/system-preset/91-tripleo-container-shutdown.preset exists
|
|
||||||
stat:
|
|
||||||
path: /usr/lib/systemd/system-preset/91-tripleo-container-shutdown.preset
|
|
||||||
register: tripleo_container_shutdown
|
|
||||||
- name: Include tasks for systemd shutdown service
|
|
||||||
include_tasks: shutdown.yml
|
|
||||||
when:
|
|
||||||
- not tripleo_container_shutdown.stat.exists
|
|
||||||
|
|
||||||
- name: "Manage containers from {{ tripleo_container_manage_config }}"
|
- name: "Manage containers from {{ tripleo_container_manage_config }}"
|
||||||
when:
|
when:
|
||||||
|
@ -82,8 +73,3 @@
|
||||||
include_tasks: delete_orphan.yml
|
include_tasks: delete_orphan.yml
|
||||||
- name: "Create containers from {{ tripleo_container_manage_config }}"
|
- name: "Create containers from {{ tripleo_container_manage_config }}"
|
||||||
include_tasks: create.yml
|
include_tasks: create.yml
|
||||||
- name: "Show all container commands for {{ tripleo_container_manage_config }}"
|
|
||||||
debug:
|
|
||||||
msg: "{{ all_containers_commands | default('No container action') }}"
|
|
||||||
when:
|
|
||||||
- ansible_check_mode|bool
|
|
||||||
|
|
|
@ -107,15 +107,3 @@
|
||||||
container_data: "{{ batched_container_data }}"
|
container_data: "{{ batched_container_data }}"
|
||||||
valid_exit_codes: "{{ tripleo_container_manage_valid_exit_code }}"
|
valid_exit_codes: "{{ tripleo_container_manage_valid_exit_code }}"
|
||||||
debug: "{{ tripleo_container_manage_debug | bool }}"
|
debug: "{{ tripleo_container_manage_debug | bool }}"
|
||||||
register: container_status_results
|
|
||||||
|
|
||||||
- name: "Create fact for containers which changed"
|
|
||||||
set_fact:
|
|
||||||
# List of containers which have changed (created or updated)
|
|
||||||
containers_changed: "{{ container_status_results.changed_containers | default([]) }}"
|
|
||||||
|
|
||||||
- name: "Append the list of all podman commands that are run for containers with changes"
|
|
||||||
set_fact:
|
|
||||||
all_containers_commands: "{{ container_status_results.commands | default([]) + (all_containers_commands | default([]) | list) }}"
|
|
||||||
when:
|
|
||||||
- ansible_check_mode|bool
|
|
||||||
|
|
|
@ -54,10 +54,3 @@
|
||||||
container_async_results: "{{ exec_async_poll_results.results }}"
|
container_async_results: "{{ exec_async_poll_results.results }}"
|
||||||
container_data: "{{ batched_container_data | haskey(attribute='action', value='exec') }}"
|
container_data: "{{ batched_container_data | haskey(attribute='action', value='exec') }}"
|
||||||
debug: "{{ tripleo_container_manage_debug | bool }}"
|
debug: "{{ tripleo_container_manage_debug | bool }}"
|
||||||
register: container_exec_status_results
|
|
||||||
|
|
||||||
- name: "Append the list of all podman commands with the containers execs"
|
|
||||||
set_fact:
|
|
||||||
all_containers_commands: "{{ container_status_results.commands | default([]) + (all_containers_commands | default([]) | list) }}"
|
|
||||||
when:
|
|
||||||
- ansible_check_mode|bool
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
- podman_drop_in.stat.exists
|
- podman_drop_in.stat.exists
|
||||||
|
|
||||||
- name: Create TripleO Container systemd service
|
- name: Create TripleO Container systemd service
|
||||||
|
become: true
|
||||||
block:
|
block:
|
||||||
- name: "Deploy tripleo-container-shutdown and tripleo-start-podman-container"
|
- name: "Deploy tripleo-container-shutdown and tripleo-start-podman-container"
|
||||||
copy:
|
copy:
|
||||||
|
|
Loading…
Reference in New Issue