From 5a4f039fc0f3fa87520516bf60a0a53dc2722a09 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Tue, 2 Jul 2024 21:32:34 +0200 Subject: [PATCH] Detect architecture of host machine for LXC images Tested for amd64/x86_64 and arm64/aarch64 --- create_inventory_lxc.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/create_inventory_lxc.yml b/create_inventory_lxc.yml index 4ac9fc5..f04eca5 100644 --- a/create_inventory_lxc.yml +++ b/create_inventory_lxc.yml @@ -17,6 +17,14 @@ #service_password: {{ service_username }} #service_ssh_keys: {{ ssh_keys }} + # architecture mapping from "uname -m" to package + architecture_mapping: + aarch64: arm64 + x86_64: amd64 + #ppc64le: ppc64el + #s390x: s390x + #armv7l: armhf + # "*cmdline_" must be listed AFTER "^cmdline_"! cmdline_python: alpine: @@ -96,12 +104,19 @@ delegate_to: "{{ ansible_host|default('localhost') }}" + - name: Get architecture + shell: "uname -m || true" + changed_when: false + register: lxc_host_arch_native + delegate_to: "{{ ansible_host|default('localhost') }}" + + - name: Create LXContainer lxc_container: name: "{{ inventory_hostname }}" state: started template: download - template_options: "-a amd64 -d {{ os_d }} -r {{ os_r }} {% if 'no-validate' in lxc_download_validate.stdout %}--no-validate{% endif %}" + template_options: "-a {{ architecture_mapping[lxc_host_arch_native.stdout] }} -d {{ os_d }} -r {{ os_r }} {% if 'no-validate' in lxc_download_validate.stdout %}--no-validate{% endif %}" config: "{{ lxc_config_file|default('/etc/lxc/ansible.conf') }}" container_config: - "lxc.group = {{ os_d }}"