--- # 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. - name : Create volume shell: | if [[ "$(ls -lh /var/lib/machines.raw | awk '{print $5}')" != "{{ lxc_host_machine_volume_size }}.0G" ]]; then if [[ ! -f "/var/lib/machines.raw" ]]; then truncate -s {{ lxc_host_machine_volume_size }}G /var/lib/machines.raw exit 3 fi fi register: machines_create changed_when: machines_create.rc == 3 failed_when: machines_create.rc not in [0, 3] args: executable: /bin/bash when: - lxc_image_cache_refresh | bool # In later versions of SystemD this is automatically done for us # by the machinectl cli on first run. - name: Format the machines file filesystem: fstype: btrfs dev: /var/lib/machines.raw when: - machines_create | changed # 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" recurse: true # 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 when: - machines_create | changed # 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 when: - machines_create | changed # 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 when: - machines_create | changed - name: Reload the System daemon command: "systemctl daemon-reload" when: > mount_unit | changed or machined_unit | changed or machine1_conf | changed - name: Restart dbus command: "systemctl reload dbus.service" when: - machine1_conf | changed # Ignore the Ansible warning here about using 'mount' via the shell module # instead of using the mount Ansible module. - name: Mount all shell: "mount | grep '/var/lib/machines' || (systemctl start var-lib-machines.mount && exit 3)" args: warn: no register: mount_machines changed_when: mount_machines.rc == 3 failed_when: mount_machines.rc not in [0, 3] tags: - skip_ansible_lint - name: Restart machined command: "systemctl restart systemd-machined.service" when: - machined_unit | changed # 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: "{{ item.ansible_job_id }}" register: job_result until: job_result.finished retries: 30 with_items: - "{{ prestage_image.results }}" - name: Place container rootfs unarchive: src: "/tmp/rootfs.tar.xz" dest: "/var/lib/machines/{{ lxc_container_base_name }}" remote_src: True