diff --git a/defaults/main.yml b/defaults/main.yml index 8ed01ef8..2c22ef94 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -116,3 +116,10 @@ lxc_cache_validate_certs: "yes" # name: "trusty.tgz" # sha256sum: "56c6a6e132ea7d10be2f3e8104f47136ccf408b30e362133f0dc4a0a9adb4d0c" # chroot_path: trusty/rootfs-amd64 + +# A list of files may be copied into the container image cache during its preparation. +# Example: +# lxc_container_cache_files: +# - src: "/etc/openstack_deploy/files/etc/issue" +# dest: "/etc/issue" +lxc_container_cache_files: [] diff --git a/tasks/lxc_cache_preparation.yml b/tasks/lxc_cache_preparation.yml index 6d18be39..17f41503 100644 --- a/tasks/lxc_cache_preparation.yml +++ b/tasks/lxc_cache_preparation.yml @@ -13,6 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Copy files from deployment host to the container cache + copy: + src: "{{ item[1].src }}" + dest: "{{ lxc_container_cache_path }}/{{ item[0].chroot_path }}/{{ item[1].dest }}" + owner: "{{ item[1].owner | default('root') }}" + group: "{{ item[1].group | default('root') }}" + mode: "{{ item[1].mode | default('644') }}" + with_nested: + - lxc_container_caches + - lxc_container_cache_files + tags: + - lxc-cache + - lxc-cache-copy-files + - name: Create apt repos in the cached container template: src: sources.list.j2 diff --git a/tests/files/container-file-copy-test.txt b/tests/files/container-file-copy-test.txt new file mode 100644 index 00000000..0541c930 --- /dev/null +++ b/tests/files/container-file-copy-test.txt @@ -0,0 +1 @@ +This is a test file to verify that the container cache file copy worked. diff --git a/tests/test.yml b/tests/test.yml index 04470bce..c6759f9b 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -42,6 +42,9 @@ name: "trusty.tgz" sha256sum: "56c6a6e132ea7d10be2f3e8104f47136ccf408b30e362133f0dc4a0a9adb4d0c" chroot_path: trusty/rootfs-amd64 + lxc_container_cache_files: + - src: files/container-file-copy-test.txt + dest: /tmp/file-copied-from-deployment-host.txt post_tasks: - name: Open sysctl file slurp: @@ -72,6 +75,14 @@ shell: | cat files/expected-lxc-net-bridge.cfg register: expected_interface_file + - name: Get the deployed test file from the container cache + slurp: + src: /var/cache/lxc/trusty/rootfs-amd64/tmp/file-copied-from-deployment-host.txt + register: copied_file + - name: Get the expected test file which should have been copied + slurp: + src: files/container-file-copy-test.txt + register: expected_copied_file - name: Get bridge interface facts setup: filter: ansible_lxcbr0 @@ -84,4 +95,5 @@ - "container_cache_dir.stat.isdir" - "container_tar_file.stat.exists" - "interface_file.stdout | match(expected_interface_file.stdout)" + - "copied_file.content | match(expected_copied_file.content)" - "lxcbr0_facts.ansible_facts.ansible_lxcbr0.ipv4.address | match('10.100.100.1')"