openstack-ansible-nspawn_hosts/tasks/nspawn_cache.yml
Kevin Carter 61380b711f
Update qgroup messages
This change will provide additional insight to the deployer should an
error from qgroup settings be raised.

Change-Id: I16bb8c33ec83890e2e354822c94476bd97e3988c
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-05-14 21:33:47 -05:00

107 lines
3.7 KiB
YAML

---
# Copyright 2018, 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: Remove old image cache
command: "btrfs subvolume delete /var/lib/machines/{{ nspawn_container_base_name }}"
register: cache_refresh_del
changed_when: cache_refresh_del.rc == 0
failed_when: cache_refresh_del.rc not in [0, 1]
when:
- nspawn_image_cache_refresh | bool
- name: Add image cache
command: "btrfs subvolume create /var/lib/machines/{{ nspawn_container_base_name }}"
register: cache_refresh_add
changed_when: cache_refresh_add.rc == 0
failed_when: cache_refresh_add.rc not in [0, 1]
when:
- nspawn_image_cache_refresh | bool
- name: Set the qgroup limits
block:
- name: Set the qgroup size|compression limits on machines
command: "btrfs qgroup limit {{ item }} /var/lib/machines/{{ nspawn_container_base_name }}"
changed_when: false
with_items:
- "-e {{ nspawn_host_qgroup_space_limit }}"
- "-c {{ nspawn_host_qgroup_compression_limit }}"
when:
- not nspawn_host_machine_quota_disabled
rescue:
- name: Notice regarding quota system
debug:
msg: >-
There was an error processing the setup of qgroups. Check the system
to ensure they're available otherwise disable the quota system by
setting `nspawn_host_machine_quota_disabled` to true.
- name: Ensure image has been pre-staged
async_status:
jid: "{{ prestage_image.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 60
when:
- nspawn_image_cache_refresh | bool
- name: Place container rootfs
unarchive:
src: "/tmp/{{ cache_basename }}"
dest: "/var/lib/machines/{{ nspawn_container_base_name }}"
remote_src: True
notify:
- Remove rootfs archive
when:
- nspawn_image_cache_refresh | bool
- name: Cached image preparation script
template:
src: "prep-scripts/nspawn_{{ nspawn_cache_map.distro }}_prep.sh.j2"
dest: "/var/lib/machines/{{ nspawn_container_base_name }}/usr/local/bin/cache-prep-commands.sh"
mode: "0755"
# This task runs several commands against the cached image to speed up the
# nspawn_container_create playbook.
- name: Prepare cached image setup commands
shell: "chroot /var/lib/machines/{{ nspawn_container_base_name }} /usr/local/bin/cache-prep-commands.sh > /var/log/nspawn-cache-prep-commands.log 2>&1"
changed_when: false
- name: Sync files from the host into the container cache
shell: |
if [[ -e "{{ item }}" ]]; then
rsync -av "{{ item }}" "/var/lib/machines/{{ nspawn_container_base_name }}{{ item }}"
else
exit 3
fi
changed_when: _rsync_container_cache.rc == 0
failed_when: _rsync_container_cache.rc not in [0, 3]
register: _rsync_container_cache
args:
executable: "/bin/bash"
with_items: "{{ (nspawn_copy_from_host | union(nspawn_container_cache_files_from_host)) | list }}"
when:
- nspawn_image_cache_refresh | bool
- name: Create networkd directory
file:
path: "/var/lib/machines/{{ nspawn_container_base_name }}/etc/systemd/network"
state: directory
- name: Create static MACs in the container
copy:
src: "/etc/systemd/network/99-default.link"
dest: "/var/lib/machines/{{ nspawn_container_base_name }}/etc/systemd/network/99-default.link"
remote_src: true