Files
openstack-ansible-lxc_hosts/tasks/lxc_cache_create.yml
Kevin Carter 42545f1c3c Use machinectl to manage image caches
This change modifies the LXC image cache system to use machine control,
which is part of systemd, to manage images for us. This will give us
insight into the cached images which we had not had before all through
the `machinectl` cli utility. This change also modifies the image fetch
process allowing it to be faster and more transparent to the enduser.
Part of the slowness in image fetching and caching is that it happens on
every run even if it's not needed. This change will now check the cache
expiry and state of the image within `machinectl` and only run the cache
update when needed or instructed to do so.

Documentation on what can be done with the `machinectl` CLI utility can
be found here:
* https://www.freedesktop.org/software/systemd/man/machinectl.html

Change-Id: Ic7f8bf400ec5781b4be67539bc6c1523069d0ab2
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2017-04-15 05:33:10 +00:00

95 lines
2.9 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.
- 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 }}/"
notify: Destroy base container
tags:
- skip_ansible_lint
- name: Update LXC image meta data
get_url:
url: "{{ lxc_image_cache_server }}/{{ item.split(';')[-1] }}/meta.tar.xz"
dest: "/tmp/meta.tar.xz"
with_items: "{{ lxc_images }}"
when:
- item | match("^{{ cache_index_item }}")
- name: Place container metadata
unarchive:
src: "/tmp/meta.tar.xz"
dest: "{{ cache_path_fact }}"
remote_src: True
- 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
environment: "{{ lxc_cache_environment }}"
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
environment: "{{ lxc_cache_environment }}"
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'