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
|
- name: Destroy base container
|
||||||
lxc_container:
|
lxc_container:
|
||||||
name: "cache-{{ lxc_cache_map.distro }}"
|
name: "LXC_NAME"
|
||||||
state: absent
|
state: absent
|
||||||
register: cache_destroy
|
register: cache_destroy
|
||||||
retries: 3
|
retries: 3
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
- name: Create container
|
- name: Create base container
|
||||||
lxc_container:
|
lxc_container:
|
||||||
name: "cache-{{ lxc_cache_map.distro }}"
|
name: "LXC_NAME"
|
||||||
template: "download"
|
template: "download"
|
||||||
state: stopped
|
state: stopped
|
||||||
backing_store: "dir"
|
backing_store: "dir"
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
# provide for the options needed to properly create an LXC image archive.
|
# provide for the options needed to properly create an LXC image archive.
|
||||||
- name: Create lxc image
|
- name: Create lxc image
|
||||||
shell: |
|
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:
|
args:
|
||||||
chdir: "{{ lxc_container_cache_path }}/{{ lxc_cache_map.distro }}/{{ lxc_cache_map.release }}/{{ lxc_cache_map.arch }}/default/"
|
chdir: "{{ lxc_container_cache_path }}/{{ lxc_cache_map.distro }}/{{ lxc_cache_map.release }}/{{ lxc_cache_map.arch }}/default/"
|
||||||
notify: Destroy base container
|
notify: Destroy base container
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
- name: Copy files from deployment host to the container cache
|
- name: Copy files from deployment host to the container cache
|
||||||
copy:
|
copy:
|
||||||
src: "{{ item.src }}"
|
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') }}"
|
owner: "{{ item.owner | default('root') }}"
|
||||||
group: "{{ item.group | default('root') }}"
|
group: "{{ item.group | default('root') }}"
|
||||||
mode: "{{ item.mode | default('644') }}"
|
mode: "{{ item.mode | default('644') }}"
|
||||||
@ -31,7 +31,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -x
|
set -x
|
||||||
{{ lxc_cache_map.cache_base_commands }}
|
{{ 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"
|
mode: "0755"
|
||||||
tags:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
@ -40,7 +40,7 @@
|
|||||||
# This task runs several commands against the cached image to speed up the
|
# This task runs several commands against the cached image to speed up the
|
||||||
# lxc_container_create playbook.
|
# lxc_container_create playbook.
|
||||||
- name: Prepare cached image setup commands
|
- 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:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
- lxc-cache-update
|
- lxc-cache-update
|
||||||
@ -48,7 +48,7 @@
|
|||||||
- name: Create repos in the cached container
|
- name: Create repos in the cached container
|
||||||
copy:
|
copy:
|
||||||
content: "{{ item.value }}"
|
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
|
with_dict: lxc_cache_map.repos
|
||||||
tags:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
@ -60,14 +60,14 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -x
|
set -x
|
||||||
{{ lxc_cache_install_command }} {{ lxc_cache_map.cache_packages | join(' ') }}
|
{{ 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"
|
mode: "0755"
|
||||||
tags:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
- lxc-cache-update
|
- lxc-cache-update
|
||||||
|
|
||||||
- name: Prepare cached image with packages
|
- 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:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
- lxc-cache-update
|
- lxc-cache-update
|
||||||
@ -78,21 +78,21 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -x
|
set -x
|
||||||
{{ lxc_cache_map.cache_post_commands }}
|
{{ 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"
|
mode: "0755"
|
||||||
tags:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
- lxc-cache-update
|
- lxc-cache-update
|
||||||
|
|
||||||
- name: Post-prepare cached image setup commands
|
- 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:
|
tags:
|
||||||
- lxc-cache
|
- lxc-cache
|
||||||
- lxc-cache-update
|
- lxc-cache-update
|
||||||
|
|
||||||
- name: Adjust sshd configuration in container
|
- name: Adjust sshd configuration in container
|
||||||
lineinfile:
|
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 }}"
|
regexp: "{{ item.regexp }}"
|
||||||
line: "{{ item.line }}"
|
line: "{{ item.line }}"
|
||||||
state: present
|
state: present
|
||||||
@ -111,7 +111,7 @@
|
|||||||
|
|
||||||
- name: Deploy ssh public key into the cached image
|
- name: Deploy ssh public key into the cached image
|
||||||
lineinfile:
|
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 }}"
|
line: "{{ lxc_container_ssh_key }}"
|
||||||
create: true
|
create: true
|
||||||
tags:
|
tags:
|
||||||
|
Loading…
Reference in New Issue
Block a user