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
This commit is contained in:
parent
8d982fae4c
commit
6c12d17fed
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user