diff --git a/defaults/main.yml b/defaults/main.yml index e4efadb..f3c101c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -126,3 +126,6 @@ lxc_container_network_veth_pair: "{{ lxc_container_network_veth_pair_prefix }}_{ # Enable fixed mac address generation for an lxc container lxc_container_fixed_mac: false + +# Enable destroying then recreating containers +lxc_container_recreate: false diff --git a/releasenotes/notes/recreate-option-d78bae1fd922a84d.yaml b/releasenotes/notes/recreate-option-d78bae1fd922a84d.yaml new file mode 100644 index 0000000..f2d6e4a --- /dev/null +++ b/releasenotes/notes/recreate-option-d78bae1fd922a84d.yaml @@ -0,0 +1,6 @@ +--- +features: + - Added the ``lxc_container_recreate`` option, which will destroy then + recreate LXC containers. The container names and IP addresses will remain + the same, as will the MAC addresses of any containers using the + ``lxc_container_fixed_mac`` setting. diff --git a/tasks/container_destroy.yml b/tasks/container_destroy.yml new file mode 100644 index 0000000..a338b0a --- /dev/null +++ b/tasks/container_destroy.yml @@ -0,0 +1,26 @@ +--- +# Copyright 2017, 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: Delete container from host + lxc_container: + name: "{{ inventory_hostname }}" + state: "absent" + delegate_to: "{{ physical_host }}" + +- name: Destroy container service directories + file: + path: "/var/lib/lxc/{{ container_name }}" + state: "absent" + delegate_to: "{{ physical_host }}" diff --git a/tasks/main.yml b/tasks/main.yml index 29a3be7..5801d17 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -48,6 +48,12 @@ tags: - always +- include: container_destroy.yml + when: + - lxc_container_recreate | bool + tags: + - lxc-container-recreate + - include: container_create.yml when: - physical_host is defined