tasks: container_create: Use lxc-clone as fallback to lxc-copy

lxc-copy is only available to lxc >= 2.0.0 so we need to use the
deprecated lxc-clone tool for older lxc releases.

Change-Id: I8513ac7c68f5e2865ff0532ad9409c3ec4c0ab9d
This commit is contained in:
Markos Chandras 2017-07-28 11:06:16 +01:00 committed by Kevin Carter (cloudnull)
parent e88e41c4af
commit b8026ad402
1 changed files with 25 additions and 9 deletions

View File

@ -102,15 +102,31 @@
# the '-B' option is used, instead of the more understandable
# '--backingstore'.
# TODO(odyssey4me): Revisit this once a fix has merged
- name: Create container (copy-on-write backing store)
command: >
lxc-copy --snapshot -B {{ lxc_container_backing_store }}
--name {{ lxc_container_base_name }}
--newname {{ inventory_hostname }}
-L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
--logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
--logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }}
delegate_to: "{{ physical_host }}"
# NOTE(hwoarang) lxc-copy is only available since lxc-2.0.0 so emulate
# its behavior using the old lxc-clone command. This is only a problem
# on openSUSE so it's safe to remove it when lxc-2.X becomes the default
# option for openSUSE in the openstack-ansible-lxc_hosts role.
- block:
- name: Create container (copy-on-write backing store)
command: >
lxc-copy --snapshot -B {{ lxc_container_backing_store }}
--name {{ lxc_container_base_name }}
--newname {{ inventory_hostname }}
-L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
--logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
--logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }}
delegate_to: "{{ physical_host }}"
rescue:
# NOTE(hwoarang) lxc-clone does not support the common
# --logfile/logpriority options so we just redirect everything to the log
# which is probably the best we can do.
- name: Create container (copy-on-write backing store) (fallback)
shell: >
lxc-clone -s -B {{ lxc_container_backing_store }} -L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
{{ lxc_container_base_name }} {{ inventory_hostname }} &>>
{{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
delegate_to: "{{ physical_host }}"
when: >
(lxc_container_backing_store == "overlayfs" or
(lxc_container_backing_store == 'lvm' and