openstack-ansible-lxc_hosts/tasks/lxc_cache_preparation_systemd_old.yml
Kevin Carter 7e98da3d0f Convert lxc_hosts role to use simple download URL
For a very long time we've been parsing and using the lxc images as
provided by upstream lxc. While these images are functional there are by
no means optimal. In general they're quite a bit larger than they need
to be and contian a lot of little sharp edges that have cut us over
the years. This change removes all of the lxc image cache parsing and
meta-data linking and simply downloads the rootfs a given url. To
maintain compatibility with the legacy images a script has been created
to parse the image index and return the legacy image url.

The result of this change:

* Access to smaller more optimal base image which is well known by the
  corresponding communities.

* Deployers now have the ability to set and forget the download url for an
  internal image instead of having to create a cache infrastructure
  compatible with the lxc download template.

* Any rootfs tarball will work as an image.

* Fewer tasks are executed and less memory is consumed resulting in faster
  deployment times.

* The base cache has a uniform meta-data setup giving all container
  types the same access to config, devices, and templating.

Change-Id: I1775e775bbb7fe86bdffdd8296c2cff5ebc5bac8
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-03-21 23:52:53 +00:00

144 lines
5.2 KiB
YAML

---
# Copyright 2015, 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.
# NOTE(cloudnull): This is only used when running SystemD <= 219
# ==============================================================
# In later versions of SystemD this is automatically done for us
# by the machinectl cli on first run. To ensure we're handling the
# case of a mount point being just offline, we first try and start
# the systemd mount unit and then check for the mount points existance.
- name: Check machinectl mount point
shell: |
mount -a || true
systemctl start var-lib-machines.mount || true
sleep 1
grep -w '/var/lib/machines' /proc/mounts
args:
warn: no
failed_when: false
changed_when: false
register: machinectl_mount
tags:
- skip_ansible_lint
# NOTE(odyssey4me):
# The size is forced to be set in Gigabytes to maintain compatibility
# with the initial implementation done in Pike-Rocky. Do not change
# this without implementing some way of converting any pre-existing
# value properly during a major upgrade.
- name: Create systemd sparse file
shell: |
truncate -s '>{{ lxc_host_machine_volume_size | regex_replace("\D*$", "") }}G' /var/lib/machines.raw
- name: Old systemd machinectl mount
block:
# In later versions of SystemD this is automatically done for us
# by the machinectl cli on first run.
- name: Format the machines sparse file
filesystem:
fstype: btrfs
dev: /var/lib/machines.raw
# In later versions of SystemD this is automatically done for us
# by the machinectl cli on first run.
- name: Create machines mount point
file:
path: "/var/lib/machines"
state: "directory"
# In later versions of SystemD this unit file has been corrected
# and is packaged with systemd proper.
- name: Move machines mount into place
copy:
src: var-lib-machines.mount
dest: /etc/systemd/system/var-lib-machines.mount
register: mount_unit
notify:
- Start machines mount
# In later versions of SystemD this is not needed. Referenced in
# the following ML post resolves the bug.
# * https://lists.freedesktop.org/archives/systemd-devel/2015-March/029151.html
- name: Move machined service into place
template:
src: systemd-machined.service.j2
dest: /etc/systemd/system/systemd-machined.service
register: machined_unit
notify:
- Reload systemd units
- Restart machined
# In later versions of SystemD this is not needed. Referenced in
# the following commit resolves the bug.
# * https://cgit.freedesktop.org/systemd/systemd/commit/src/machine/org.freedesktop.machine1.conf?id=72c3897f77a7352618ea76b880a6764f52d6327b
- name: Move machine1 dbus config into place
copy:
src: org.freedesktop.machine1.conf
dest: /etc/dbus-1/system.d/org.freedesktop.machine1.conf
register: machine1_conf
notify:
- Reload systemd units
- Restart dbus
when:
- machinectl_mount.rc != 0
# Ensure lxc networks are running as they're supposed to
- meta: flush_handlers
# NOTE(cloudnull): Because the machines mount may be a manually created sparse
# file we run an online resize to ensure the machines mount is
# the size we expect.
- name: Ensure the machines fs is sized correctly
command: "btrfs filesystem resize max /var/lib/machines"
changed_when: false
- name: Disable the machinectl quota system
command: "btrfs quota {{ lxc_host_machine_quota_disabled | bool | ternary('disable', 'enable') }} /var/lib/machines"
changed_when: false
# Because of this post and it's related bug(s) this is adding the container
# volumes the old way. The new way would simply be calling `machinectl`.
# * https://www.mail-archive.com/systemd-devel@lists.freedesktop.org/msg28255.html
- name: Remove old image cache
command: "btrfs subvolume delete /var/lib/machines/{{ lxc_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:
- lxc_image_cache_refresh | bool
- name: Add image cache
command: "btrfs subvolume create /var/lib/machines/{{ lxc_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:
- lxc_image_cache_refresh | bool
- name: Ensure image has been pre-staged
async_status:
jid: "{{ prestage_image.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 60
- name: Place container rootfs
unarchive:
src: "/tmp/{{ cache_basename }}"
dest: "/var/lib/machines/{{ lxc_container_base_name }}"
remote_src: True
notify:
- Remove rootfs archive