diff --git a/handlers/main.yml b/handlers/main.yml index 8eb5ee1e..afe20b1a 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -37,12 +37,26 @@ name: "systemd-machined.service" state: "restarted" -- name: Start machines mount +- name: Enable machines mount systemd: daemon_reload: yes name: "var-lib-machines.mount" enabled: "yes" - state: "started" + listen: Start machines mount + +# NOTE(cloudnull): The systemd module is not used to start the +# mount because we dont want to "restart" the +# mount unnecessarily. To ensure we're able to +# load new options without requiring a mount +# restart the systemctl command is used with +# the "reload-or-restart" argument. +- name: Start or reload the machines mount + command: "systemctl reload-or-restart var-lib-machines.mount" + args: + warn: no + listen: Start machines mount + tags: + - skip_ansible_lint - name: Restart irqbalance service: diff --git a/tasks/lxc_cache_preparation.yml b/tasks/lxc_cache_preparation.yml index 20d8568b..f0208003 100644 --- a/tasks/lxc_cache_preparation.yml +++ b/tasks/lxc_cache_preparation.yml @@ -46,6 +46,8 @@ when: - (deployment_environment_variables | default({})).keys() | length > 0 +- include_tasks: lxc_volume.yml + - include_tasks: "lxc_cache_preparation_systemd_{{ (systemd_version.stdout_lines[0].split()[-1] | int > 219) | ternary('new', 'old') }}.yml" - block: diff --git a/tasks/lxc_cache_preparation_systemd_new.yml b/tasks/lxc_cache_preparation_systemd_new.yml index 639da3e1..2b049d92 100644 --- a/tasks/lxc_cache_preparation_systemd_new.yml +++ b/tasks/lxc_cache_preparation_systemd_new.yml @@ -15,21 +15,6 @@ # NOTE(cloudnull): When modern SystemD is running everywhere this can be # collapsed back into the base preparation task file. -# 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: Set volume size - shell: machinectl set-limit {{ lxc_host_machine_volume_size | regex_replace('\D*$', '') }}G - changed_when: false - args: - executable: /bin/bash - -- name: Disable the machinectl quota system - command: "btrfs quota {{ lxc_host_machine_quota_disabled | bool | ternary('disable', 'enable') }} /var/lib/machines" - changed_when: false - - name: Remove old image cache command: "machinectl remove {{ lxc_container_base_name }}" register: cache_refresh diff --git a/tasks/lxc_cache_preparation_systemd_old.yml b/tasks/lxc_cache_preparation_systemd_old.yml index 536805b5..a61bcbb2 100644 --- a/tasks/lxc_cache_preparation_systemd_old.yml +++ b/tasks/lxc_cache_preparation_systemd_old.yml @@ -13,101 +13,33 @@ # 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 +# 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 -# 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 +# 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 # 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 diff --git a/tasks/lxc_volume.yml b/tasks/lxc_volume.yml new file mode 100644 index 00000000..84f7dc9e --- /dev/null +++ b/tasks/lxc_volume.yml @@ -0,0 +1,88 @@ +--- +# Copyright 2017, 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: Check machinectl mount point + command: mountpoint /var/lib/machines + failed_when: false + changed_when: false + register: machinectl_mount + +# 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: Set volume size + shell: | + if ! machinectl set-limit {{ lxc_host_machine_volume_size | regex_replace("\D*$", "") }}G; then + truncate -s '>{{ lxc_host_machine_volume_size | regex_replace("\D*$", "") }}G' /var/lib/machines.raw + fi + changed_when: false + register: machines_create + args: + executable: /bin/bash + tags: + - skip_ansible_lint + +- name: Systemd machinectl mount + block: + - name: Format the machines sparse file + filesystem: + fstype: btrfs + dev: /var/lib/machines.raw + + - name: Create machines mount point + file: + path: "/var/lib/machines" + state: "directory" + + - name: Move machines mount into place + template: + src: var-lib-machines.mount + dest: /etc/systemd/system/var-lib-machines.mount + register: mount_unit + notify: + - Reload systemd units + - Start machines mount + when: + - machinectl_mount.rc != 0 + +- meta: flush_handlers + +- name: Disable the machinectl quota system + command: "btrfs quota {{ lxc_host_machine_quota_disabled | bool | ternary('disable', 'enable') }} /var/lib/machines" + args: + executable: /bin/bash + failed_when: false + register: machines_create + tags: + - skip_ansible_lint + +- name: Notice quota system was not disabled + debug: + msg: >- + The machinectl quota system could not be disabled. This typically + means it is already off or not available on the system. + when: + - machines_create.rc != 0 + +# 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" + failed_when: false + when: + - machines_create is changed diff --git a/files/var-lib-machines.mount b/templates/var-lib-machines.mount similarity index 73% rename from files/var-lib-machines.mount rename to templates/var-lib-machines.mount index 0d72c163..4c005003 100644 --- a/files/var-lib-machines.mount +++ b/templates/var-lib-machines.mount @@ -13,4 +13,4 @@ ConditionPathExists=/var/lib/machines.raw What=/var/lib/machines.raw Where=/var/lib/machines Type=btrfs -Options=loop \ No newline at end of file +Options=loop,defaults,noatime,nodiratime,compress=lzo,commit=120,{{ (ansible_kernel is version_compare('4.5', '>=')) | ternary('space_cache=v2', 'space_cache') }}