On container destroy remove container journal
When a container is destroyed ensure that the journal, which is likley being written to the host is also removed. Change-Id: I9f7493b80c0b8c9d064fb8ce16fb305a7c944a94 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
08dcc639eb
commit
af63bc0c28
23
playbooks/common-tasks/remove_container_journal.yml
Normal file
23
playbooks/common-tasks/remove_container_journal.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
# Copyright 2018, Rackspace US, Inc.
|
||||||
|
#
|
||||||
|
# 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: Destroy container journal directories
|
||||||
|
file:
|
||||||
|
path: "/var/log/journal/{{ container_machine_id }}"
|
||||||
|
state: "absent"
|
||||||
|
delegate_to: "{{ physical_host }}"
|
||||||
|
when:
|
||||||
|
- not _container_machine_id is failed
|
||||||
|
- force_containers_destroy | bool
|
@ -32,6 +32,15 @@
|
|||||||
gather_facts: false
|
gather_facts: false
|
||||||
user: root
|
user: root
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Slurp machine-id
|
||||||
|
slurp:
|
||||||
|
src: "/etc/machine-id"
|
||||||
|
register: _container_machine_id
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
tags:
|
||||||
|
- always
|
||||||
|
|
||||||
- name: Destroy a container
|
- name: Destroy a container
|
||||||
lxc_container:
|
lxc_container:
|
||||||
name: "{{ container_name }}"
|
name: "{{ container_name }}"
|
||||||
@ -40,6 +49,11 @@
|
|||||||
when:
|
when:
|
||||||
- force_containers_destroy | bool
|
- force_containers_destroy | bool
|
||||||
- force_containers_data_destroy | bool
|
- force_containers_data_destroy | bool
|
||||||
|
|
||||||
|
- include_tasks: "common-tasks/remove_container_journal.yml"
|
||||||
|
vars:
|
||||||
|
container_machine_id: "{{ ((_container_machine_id.content | default('bm9uZQo=')) | b64decode).strip() }}"
|
||||||
|
|
||||||
- name: Destroy container service directories
|
- name: Destroy container service directories
|
||||||
file:
|
file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
|
@ -50,6 +50,12 @@
|
|||||||
register: systemd_escape
|
register: systemd_escape
|
||||||
delegate_to: "{{ physical_host }}"
|
delegate_to: "{{ physical_host }}"
|
||||||
|
|
||||||
|
- name: Get machine-id
|
||||||
|
command: >-
|
||||||
|
hostnamectl --machine="{{ inventory_hostname }}" status | awk '/Machine ID/ {print $3}'
|
||||||
|
register: _container_machine_id
|
||||||
|
delegate_to: "{{ physical_host }}"
|
||||||
|
|
||||||
- name: Disable container
|
- name: Disable container
|
||||||
systemd:
|
systemd:
|
||||||
name: "systemd-nspawn@{{ systemd_escape.stdout }}"
|
name: "systemd-nspawn@{{ systemd_escape.stdout }}"
|
||||||
@ -75,6 +81,10 @@
|
|||||||
- machinectl_image_status.rc == 0
|
- machinectl_image_status.rc == 0
|
||||||
- force_containers_destroy | bool
|
- force_containers_destroy | bool
|
||||||
|
|
||||||
|
- include_tasks: "common-tasks/remove_container_journal.yml"
|
||||||
|
vars:
|
||||||
|
container_machine_id: "{{ (_container_machine_id.stdout).strip() }}"
|
||||||
|
|
||||||
- name: Destroy container data
|
- name: Destroy container data
|
||||||
file:
|
file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
|
Loading…
Reference in New Issue
Block a user