diff --git a/defaults/main.yml b/defaults/main.yml index ba0a9bc7..9f324e5e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -252,3 +252,11 @@ lxc_centos_package_key: https://copr-be.cloud.fedoraproject.org/results/thm/lxc2 # 'lxc_hosts_opensuse_mirror_obs_url' to its default value. lxc_hosts_opensuse_mirror_url: "{{ opensuse_mirror | default('http://download.opensuse.org') }}" lxc_hosts_opensuse_mirror_obs_url: "{{ lxc_hosts_opensuse_mirror_url }}" + +## A list of 'legacy' lxc configuration keys and their corresponding new +## keys. Use this map to substitute keys suitable for other/newer lxc versions +lxc_config_key_mapping: + 3: + uts_name: lxc.uts.name + 2: + uts_name: lxc.utsname diff --git a/tasks/lxc_post_install.yml b/tasks/lxc_post_install.yml index 21e1efcc..f5443e67 100644 --- a/tasks/lxc_post_install.yml +++ b/tasks/lxc_post_install.yml @@ -38,8 +38,19 @@ - lxc-files - lxc-config +- name: Pull lxc version + command: "lxc-ls --version" + changed_when: false + register: lxc_version + tags: + - skip_ansible_lint + +- name: Enable or Disable lxc three syntax + set_fact: + lxc_major_version: "{{ lxc_version.stdout.split('.')[0] }}" + - name: Create machinectl base template - copy: + template: src: "lxc-machinectl.j2" dest: "/usr/share/lxc/templates/lxc-machinectl" owner: "root" diff --git a/files/lxc-machinectl.j2 b/templates/lxc-machinectl.j2 similarity index 98% rename from files/lxc-machinectl.j2 rename to templates/lxc-machinectl.j2 index c212264f..c0ca05a7 100644 --- a/files/lxc-machinectl.j2 +++ b/templates/lxc-machinectl.j2 @@ -161,7 +161,7 @@ if [ -e "${LXC_CACHE_PATH}/fstab" ]; then fi # Set the uts name -echo "lxc.utsname = ${LXC_NAME}" >> "${LXC_PATH}/config" +echo "{{ lxc_config_key_mapping[lxc_major_version|int]['uts_name'] }} = ${LXC_NAME}" >> "${LXC_PATH}/config" # Look for extra templates TEMPLATE_FILES="${LXC_PATH}/config"