101 lines
2.9 KiB
YAML
101 lines
2.9 KiB
YAML
---
|
|
# Copyright 2020, BBC R&D
|
|
#
|
|
# 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 sparse machines file
|
|
command: "truncate -s 11G /var/lib/machines.raw"
|
|
args:
|
|
creates: /var/lib/machines.raw
|
|
register: machines_create
|
|
|
|
- name: Format the machines file
|
|
filesystem:
|
|
fstype: ext4
|
|
dev: /var/lib/machines.raw
|
|
when:
|
|
- machines_create is changed
|
|
|
|
- name: Create machines mount point
|
|
file:
|
|
path: "/var/lib/machines"
|
|
state: "directory"
|
|
recurse: true
|
|
|
|
- name: Move machines mount into place
|
|
copy:
|
|
src: var-lib-machines.mount
|
|
dest: /lib/systemd/system/var-lib-machines.mount
|
|
register: mount_unit
|
|
|
|
- name: Reload the System daemon
|
|
systemd:
|
|
daemon_reload: yes
|
|
when: mount_unit is changed
|
|
|
|
- name: Mount all
|
|
shell: "mount | grep '/var/lib/machines' || (systemctl start var-lib-machines.mount && exit 3)"
|
|
register: mount_machines
|
|
changed_when: mount_machines.rc == 3
|
|
failed_when: mount_machines.rc not in [0, 3]
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
- name: Remove the old image cache
|
|
file:
|
|
path: "/var/lib/machines/{{ lxc_container_base_name }}"
|
|
state: absent
|
|
when:
|
|
- lxc_image_cache_refresh | bool
|
|
|
|
- name: Create new image cache directory
|
|
file:
|
|
path: "/var/lib/machines/{{ lxc_container_base_name }}"
|
|
state: directory
|
|
register: create_new_dir
|
|
|
|
- name: Wait for base image download
|
|
async_status:
|
|
jid: "{{ prestage_image.ansible_job_id }}"
|
|
register: _lxc_prestage_image_result
|
|
until: _lxc_prestage_image_result.finished
|
|
delay: 5
|
|
retries: "{{ lxc_cache_prep_timeout | int // 5 }}"
|
|
|
|
- name: Unpack base image
|
|
unarchive:
|
|
src: "/tmp/{{ cache_basename }}"
|
|
dest: "/var/lib/machines/{{ lxc_container_base_name }}"
|
|
remote_src: yes
|
|
extra_opts: "{{ _lxc_hosts_unarchive_extra_opts | default(omit) }}"
|
|
when: create_new_dir is changed
|
|
|
|
# NOTE(jrosser) Centos 8.3 images ships as a nested tar file, these tasks unpack and remove
|
|
# the inner tar file
|
|
- name: Unpack nested tar file
|
|
unarchive:
|
|
src: "/var/lib/machines/{{ lxc_container_base_name }}/{{ _lxc_hosts_nested_tar_file }}"
|
|
dest: "/var/lib/machines/{{ lxc_container_base_name }}"
|
|
remote_src: yes
|
|
when:
|
|
- create_new_dir is changed
|
|
- _lxc_hosts_nested_tar_file is defined
|
|
|
|
- name: Remove nested tar file
|
|
file:
|
|
path: "/var/lib/machines/{{ lxc_container_base_name }}/{{ _lxc_hosts_nested_tar_file }}"
|
|
state: absent
|
|
when:
|
|
- create_new_dir is changed
|
|
- _lxc_hosts_nested_tar_file is defined
|