From 6c12d17fedf285155fe8d54672099b75ddde815f Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Wed, 4 May 2016 14:10:41 -0700 Subject: [PATCH] Fix generation of LXC hostnames The LXC download template sets hostnames within containers by an in-place string replacement of 'LXC_NAME' in /etc/hosts and /etc/hostnames with the given container name. Create the base cache container image with the name 'LXC_NAME' so that this this in-place text replacement happens and containers are created with the expected hostnames. Change-Id: I851f29d8feebc41e9bcbc1866bba1782c6727d6a --- handlers/main.yml | 2 +- tasks/lxc_cache.yml | 4 ++-- tasks/lxc_cache_create.yml | 2 +- tasks/lxc_cache_preparation.yml | 20 ++++++++++---------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 21f6ccb9..66137392 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -45,7 +45,7 @@ - name: Destroy base container lxc_container: - name: "cache-{{ lxc_cache_map.distro }}" + name: "LXC_NAME" state: absent register: cache_destroy retries: 3 diff --git a/tasks/lxc_cache.yml b/tasks/lxc_cache.yml index 0fa63970..8178515e 100644 --- a/tasks/lxc_cache.yml +++ b/tasks/lxc_cache.yml @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Create container +- name: Create base container lxc_container: - name: "cache-{{ lxc_cache_map.distro }}" + name: "LXC_NAME" template: "download" state: stopped backing_store: "dir" diff --git a/tasks/lxc_cache_create.yml b/tasks/lxc_cache_create.yml index 6cb0e4a2..1afcdf8f 100644 --- a/tasks/lxc_cache_create.yml +++ b/tasks/lxc_cache_create.yml @@ -25,7 +25,7 @@ # provide for the options needed to properly create an LXC image archive. - name: Create lxc image shell: | - tar -Opc -C /var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs . | xz -{{ lxc_image_compression_ratio }} -c - > rootfs.tar.xz + tar -Opc -C /var/lib/lxc/LXC_NAME/rootfs . | xz -{{ lxc_image_compression_ratio }} -c - > rootfs.tar.xz args: chdir: "{{ lxc_container_cache_path }}/{{ lxc_cache_map.distro }}/{{ lxc_cache_map.release }}/{{ lxc_cache_map.arch }}/default/" notify: Destroy base container diff --git a/tasks/lxc_cache_preparation.yml b/tasks/lxc_cache_preparation.yml index 17bbbcdc..92fed88f 100644 --- a/tasks/lxc_cache_preparation.yml +++ b/tasks/lxc_cache_preparation.yml @@ -16,7 +16,7 @@ - name: Copy files from deployment host to the container cache copy: src: "{{ item.src }}" - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs{{ item.dest }}" + dest: "/var/lib/lxc/LXC_NAME/rootfs{{ item.dest }}" owner: "{{ item.owner | default('root') }}" group: "{{ item.group | default('root') }}" mode: "{{ item.mode | default('644') }}" @@ -31,7 +31,7 @@ #!/usr/bin/env bash set -x {{ lxc_cache_map.cache_base_commands }} - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs/usr/local/bin/cache-prep-commands.sh" + dest: "/var/lib/lxc/LXC_NAME/rootfs/usr/local/bin/cache-prep-commands.sh" mode: "0755" tags: - lxc-cache @@ -40,7 +40,7 @@ # This task runs several commands against the cached image to speed up the # lxc_container_create playbook. - name: Prepare cached image setup commands - command: "chroot /var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs /usr/local/bin/cache-prep-commands.sh" + command: "chroot /var/lib/lxc/LXC_NAME/rootfs /usr/local/bin/cache-prep-commands.sh" tags: - lxc-cache - lxc-cache-update @@ -48,7 +48,7 @@ - name: Create repos in the cached container copy: content: "{{ item.value }}" - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs{{ item.key }}" + dest: "/var/lib/lxc/LXC_NAME/rootfs{{ item.key }}" with_dict: lxc_cache_map.repos tags: - lxc-cache @@ -60,14 +60,14 @@ #!/usr/bin/env bash set -x {{ lxc_cache_install_command }} {{ lxc_cache_map.cache_packages | join(' ') }} - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs/usr/local/bin/cache-package-prep-commands.sh" + dest: "/var/lib/lxc/LXC_NAME/rootfs/usr/local/bin/cache-package-prep-commands.sh" mode: "0755" tags: - lxc-cache - lxc-cache-update - name: Prepare cached image with packages - command: "chroot /var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs /usr/local/bin/cache-package-prep-commands.sh" + command: "chroot /var/lib/lxc/LXC_NAME/rootfs /usr/local/bin/cache-package-prep-commands.sh" tags: - lxc-cache - lxc-cache-update @@ -78,21 +78,21 @@ #!/usr/bin/env bash set -x {{ lxc_cache_map.cache_post_commands }} - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs/usr/local/bin/cache-post-prep-commands.sh" + dest: "/var/lib/lxc/LXC_NAME/rootfs/usr/local/bin/cache-post-prep-commands.sh" mode: "0755" tags: - lxc-cache - lxc-cache-update - name: Post-prepare cached image setup commands - command: "chroot /var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs /usr/local/bin/cache-post-prep-commands.sh" + command: "chroot /var/lib/lxc/LXC_NAME/rootfs /usr/local/bin/cache-post-prep-commands.sh" tags: - lxc-cache - lxc-cache-update - name: Adjust sshd configuration in container lineinfile: - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs/etc/ssh/sshd_config" + dest: "/var/lib/lxc/LXC_NAME/rootfs/etc/ssh/sshd_config" regexp: "{{ item.regexp }}" line: "{{ item.line }}" state: present @@ -111,7 +111,7 @@ - name: Deploy ssh public key into the cached image lineinfile: - dest: "/var/lib/lxc/cache-{{ lxc_cache_map.distro }}/rootfs/root/.ssh/authorized_keys" + dest: "/var/lib/lxc/LXC_NAME/rootfs/root/.ssh/authorized_keys" line: "{{ lxc_container_ssh_key }}" create: true tags: