Browse Source

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
changes/37/742237/5
Emilien Macchi 2 years ago
parent
commit
ca8fae62e4
  1. 24
      tripleo_ansible/ansible_plugins/action/container_systemd.py
  2. 1
      tripleo_ansible/roles/tripleo_container_manage/tasks/create.yml
  3. 18
      tripleo_ansible/roles/tripleo_container_manage/tasks/main.yml
  4. 12
      tripleo_ansible/roles/tripleo_container_manage/tasks/podman/create.yml
  5. 7
      tripleo_ansible/roles/tripleo_container_manage/tasks/podman/exec.yml
  6. 1
      tripleo_ansible/roles/tripleo_container_manage/tasks/shutdown.yml

24
tripleo_ansible/ansible_plugins/action/container_systemd.py

@ -57,11 +57,6 @@ options:
description:
- Whether or not we cleanup the old healthchecks with SystemD.
type: boolean
restart_containers:
description:
- List of container names to be restarted
default: []
type: list
debug:
default: false
description:
@ -324,24 +319,8 @@ class ActionModule(ActionBase):
container_config = args['container_config']
systemd_healthchecks = args['systemd_healthchecks']
restart_containers = args['restart_containers']
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 = []
for container in container_config:
for name, config in container.items():
@ -355,8 +334,7 @@ class ActionModule(ActionBase):
changed_services = self._create_units(container_config, task_vars)
if len(changed_services) > 0:
self._systemd_reload(task_vars)
service_names = set(changed_services + extra_restarts)
self._restart_services(service_names, task_vars)
self._restart_services(changed_services, task_vars)
result['changed'] = self.changed
result['restarted'] = self.restarted

1
tripleo_ansible/roles/tripleo_container_manage/tasks/create.yml

@ -25,7 +25,6 @@
container_systemd:
container_config: "{{ container_config }}"
debug: "{{ tripleo_container_manage_debug | bool }}"
restart_containers: "{{ containers_changed | default([]) }}"
systemd_healthchecks: "{{ (not tripleo_container_manage_healthcheck_disabled | bool) }}"
vars:
container_config: "{{ all_containers_hash | dict_to_list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}"

18
tripleo_ansible/roles/tripleo_container_manage/tasks/main.yml

@ -55,18 +55,9 @@
all_containers_hash: "{{ container_config_data.configs }}"
- name: "Manage systemd shutdown files"
become: true
include_tasks: shutdown.yml
when:
- tripleo_container_manage_systemd_order
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
- tripleo_container_manage_systemd_order|bool
- name: "Manage containers from {{ tripleo_container_manage_config }}"
when:
@ -82,8 +73,3 @@
include_tasks: delete_orphan.yml
- name: "Create containers from {{ tripleo_container_manage_config }}"
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

12
tripleo_ansible/roles/tripleo_container_manage/tasks/podman/create.yml

@ -107,15 +107,3 @@
container_data: "{{ batched_container_data }}"
valid_exit_codes: "{{ tripleo_container_manage_valid_exit_code }}"
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

7
tripleo_ansible/roles/tripleo_container_manage/tasks/podman/exec.yml

@ -54,10 +54,3 @@
container_async_results: "{{ exec_async_poll_results.results }}"
container_data: "{{ batched_container_data | haskey(attribute='action', value='exec') }}"
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

1
tripleo_ansible/roles/tripleo_container_manage/tasks/shutdown.yml

@ -26,6 +26,7 @@
- podman_drop_in.stat.exists
- name: Create TripleO Container systemd service
become: true
block:
- name: "Deploy tripleo-container-shutdown and tripleo-start-podman-container"
copy:

Loading…
Cancel
Save