diff --git a/defaults/main.yml b/defaults/main.yml index 512b3adc..261a5b89 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -203,6 +203,10 @@ lxc_hosts_container_build_command: "{{ _lxc_hosts_container_build_command | defa # Local path to cached image lxc_image_cache_path: "/var/lib/machines/{{ lxc_container_base_name }}" +# Expiration timeout for the cached image +# Should be in format supported by the to_time_unit filter +lxc_image_cache_expiration: "1year" + # Set this option to true to pull a new cached image. lxc_image_cache_refresh: false diff --git a/releasenotes/notes/fix_lxc_cache_expiration-1656b5758c4ec24e.yaml b/releasenotes/notes/fix_lxc_cache_expiration-1656b5758c4ec24e.yaml new file mode 100644 index 00000000..3a580c75 --- /dev/null +++ b/releasenotes/notes/fix_lxc_cache_expiration-1656b5758c4ec24e.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + Implemented variable ``lxc_image_cache_expiration`` that controlls for how + long cached LXC image will be valid. Default value is `1year`. Variable + format should be compatible with community.general.to_time_unit filter. +fixes: + - | + LXC image cache expiration mechanism has being fixed. Previously LXC images were + valid forever. diff --git a/tasks/lxc_cache.yml b/tasks/lxc_cache.yml index 60be2f40..fef2eed6 100644 --- a/tasks/lxc_cache.yml +++ b/tasks/lxc_cache.yml @@ -16,7 +16,7 @@ - name: Set LXC cache fact(s) set_fact: cache_path_fact: "{{ lxc_container_cache_path }}/{{ lxc_cache_map.distro }}/{{ lxc_cache_map.release }}/{{ lxc_cache_map.arch }}/{{ lxc_cache_default_variant }}" - cache_time: "{{ ansible_facts['date_time']['epoch'] }}" + cache_time: "{{ now().timestamp() }}" - name: Retrieve the expiry object slurp: @@ -32,7 +32,7 @@ set_fact: lxc_image_cache_refresh: true when: - cache_time >= (expiry.content|default('MQo=') | b64decode) + cache_time | int >= (expiry.content | default('MQo=') | b64decode | int) tags: - always diff --git a/tasks/lxc_cache_create.yml b/tasks/lxc_cache_create.yml index 102bbd6e..050512f2 100644 --- a/tasks/lxc_cache_create.yml +++ b/tasks/lxc_cache_create.yml @@ -48,21 +48,14 @@ - expiry - templates -- name: Set cache expiry - shell: "date -d @{{ (cache_time | int) + 31536000 }}" - changed_when: false - register: _cache_expiry - tags: - - skip_ansible_lint - - name: Set expiry copy: - content: "{{ _cache_expiry.stdout }}" + content: "{{ cache_time | int + lxc_image_cache_expiration | community.general.to_seconds | int }}" dest: "{{ cache_path_fact }}/expiry" - name: Set build ID copy: - content: "{{ cache_time }}" + content: "{{ cache_time | int }}" dest: "{{ cache_path_fact }}/build_id" - name: Create base container to use for {{ lxc_container_backing_store }}-backed containers