openstack-ansible-lxc_hosts/tasks/lxc_cache_create.yml
Jonathan Rosser dce34c0b87 Allow container creation on ZFS backing storage
Add a conditional task to create the base container on ZFS backing
storage.

Change-Id: Id6871f37aa2e7729d42acc0233ccd057706d8d24
2017-10-05 12:26:45 +01:00

126 lines
3.7 KiB
YAML

---
# Copyright 2016, 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: Create LXC cache dir
file:
path: "{{ cache_path_fact }}"
state: "directory"
recurse: true
- name: Remove existing cache archive
file:
path: "{{ cache_path_fact }}/rootfs.tar.xz"
state: "absent"
# This is using a shell command because the ansible archive module does not
# provide for the options needed to properly create an LXC image archive.
# Ansible will print a warning since this task calls 'tar' directly and we
# suppress this warning with 'warn: no'.
- name: Create lxc image
shell: |
tar -Opc -C {{ lxc_image_cache_path }} . | {{ lxc_xz_bin }} -{{ lxc_image_compression_ratio }} -c - > rootfs.tar.xz
args:
chdir: "{{ cache_path_fact }}/"
warn: no
tags:
- skip_ansible_lint
- name: Fetch LXC image-metadata
shell: >
aria2c
--max-connection-per-server=4
--continue
--allow-overwrite=true
--dir=/tmp
--out=meta.tar.xz
--check-certificate={{ (lxc_hosts_validate_certs | bool) | lower }}
{% for server in lxc_image_cache_server_mirrors %}{{ server }}/{{ item.split(';')[-1] }}/meta.tar.xz {% endfor %}
args:
warn: no
with_items:
- "{{ lxc_images }}"
tags:
- skip_ansible_lint
- always
- name: Place container metadata
unarchive:
src: "/tmp/meta.tar.xz"
dest: "{{ cache_path_fact }}"
remote_src: True
- name: Remove metadata archive
file:
path: "/tmp/meta.tar.xz"
state: "absent"
- name: Set cache expiry
shell: "date -d @{{ (cache_time | int) + 31536000 }} > {{ cache_path_fact }}/expiry"
tags:
- skip_ansible_lint
- name: Set build ID
shell: "echo {{ cache_time }} > {{ cache_path_fact }}/build_id"
tags:
- skip_ansible_lint
- name: Create base container to use for overlayfs containers
lxc_container:
name: "{{ lxc_container_base_name }}"
template: "download"
state: stopped
backing_store: "dir"
template_options: "{{ lxc_cache_download_template_options }}"
register: cache_download
retries: 3
delay: 10
until: cache_download|success
when:
- lxc_container_backing_store is defined
- lxc_container_backing_store == 'overlayfs'
- name: Create base container to use for LVM-backed copy-on-write containers
lxc_container:
name: "{{ lxc_container_base_name }}"
template: "download"
state: stopped
backing_store: "lvm"
template_options: "{{ lxc_cache_download_template_options }}"
register: cache_download
retries: 3
delay: 10
until: cache_download|success
when:
- lxc_container_backing_store is defined
- lxc_container_backing_store == 'lvm'
- lxc_container_backing_method is defined
- lxc_container_backing_method == 'copy-on-write'
- name: Create base container to use for ZFS-backed containers
lxc_container:
name: "{{ lxc_container_base_name }}"
template: "download"
state: stopped
backing_store: "zfs"
zfs_root: "{{ lxc_container_zfs_root_name }}"
template_options: "{{ lxc_cache_download_template_options }}"
register: cache_download
retries: 3
delay: 10
until: cache_download|success
when:
- lxc_container_backing_store is defined
- lxc_container_backing_store == 'zfs'