From 89dc180ca4b7be2595f8f4c5740740bc486a80af Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 9 Oct 2018 13:56:48 -0500 Subject: [PATCH] Update the option uts name in the machinectl template The machinectl template was running with the legacy uts name option. This change updates that option so that it uses the hash and major version to update the config variable. Change-Id: I85b5c92422116b139e447330214b2d6b5afbf948 Signed-off-by: Kevin Carter --- defaults/main.yml | 8 ++++++++ tasks/lxc_post_install.yml | 13 ++++++++++++- {files => templates}/lxc-machinectl.j2 | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) rename {files => templates}/lxc-machinectl.j2 (98%) 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"