diff --git a/defaults/main.yml b/defaults/main.yml index 787ff407..f6da0ba8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,6 +28,9 @@ lxc_architecture_mapping: x86_64: amd64 ppc64le: ppc64el +# Set the volume size in gigabytes for the machine image caches. +lxc_host_machine_volume_size: 8 + # lxc container rootfs directory and cache path lxc_container_directory: "/var/lib/lxc" lxc_container_cache_path: "/var/cache/lxc/download" diff --git a/tasks/lxc_cache_preparation_systemd_new.yml b/tasks/lxc_cache_preparation_systemd_new.yml index b33f548c..f6e06926 100644 --- a/tasks/lxc_cache_preparation_systemd_new.yml +++ b/tasks/lxc_cache_preparation_systemd_new.yml @@ -23,6 +23,22 @@ when: - lxc_image_cache_refresh | bool +# NOTE(cloudnull): When modern SystemD is running everywhere this can be +# collapsed back into the base preparation task file. +- name : Set volume size + shell: | + if [[ ! "$(ls -lh /var/lib/machines.raw | awk '{print $5}')" == "{{ lxc_host_machine_volume_size }}G" ]]; then + machinectl set-limit {{ lxc_host_machine_volume_size }}G + exit 3 + else + exit 0 + fi + register: machines_create + changed_when: machines_create.rc == 3 + failed_when: machines_create.rc not in [0, 3] + when: + - lxc_image_cache_refresh | bool + - name: Retrieve base image command: >- machinectl diff --git a/tasks/lxc_cache_preparation_systemd_old.yml b/tasks/lxc_cache_preparation_systemd_old.yml index b2723953..00ff2d5c 100644 --- a/tasks/lxc_cache_preparation_systemd_old.yml +++ b/tasks/lxc_cache_preparation_systemd_old.yml @@ -18,11 +18,19 @@ # ============================================================== # In later versions of SystemD this is automatically done for us # by the machinectl cli on first run. -- name: Create sparse machines file - command: "truncate -s 11G /var/lib/machines.raw" - args: - creates: /var/lib/machines.raw +- name : Create volume + shell: | + if [[ ! "$(ls -lh /var/lib/machines.raw | awk '{print $5}')" == "{{ lxc_host_machine_volume_size }}G" ]]; 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] + when: + - lxc_image_cache_refresh | bool # In later versions of SystemD this is automatically done for us # by the machinectl cli on first run.