diff --git a/playbooks/lxc-containers-create.yml b/playbooks/lxc-containers-create.yml index dbc5aa4..0b5110a 100644 --- a/playbooks/lxc-containers-create.yml +++ b/playbooks/lxc-containers-create.yml @@ -22,4 +22,5 @@ - { role: "lxc_container_create", tags: [ "lxc-container-create" ] } vars: ansible_hostname: "{{ container_name }}" - is_metal: "{{ properties.is_metal|default(false) }}" \ No newline at end of file + is_metal: "{{ properties.is_metal|default(false) }}" + lxc_container_release: "{{ properties.container_release|default('trusty') }}" diff --git a/playbooks/roles/lxc_container_create/defaults/main.yml b/playbooks/roles/lxc_container_create/defaults/main.yml index 4969649..72793c3 100644 --- a/playbooks/roles/lxc_container_create/defaults/main.yml +++ b/playbooks/roles/lxc_container_create/defaults/main.yml @@ -29,6 +29,12 @@ lxc_container_vg_name: lxc # Default image to build from lxc_container_release: trusty +lxc_container_user_password: "{{ lookup('pipe', 'date --rfc-3339=ns | sha512sum | base64 | head -c 32') }}" +lxc_container_user_name: ubuntu +lxc_container_template_options: > + --release {{ lxc_container_release }} + --user {{ lxc_container_user_name }} + --password {{ lxc_container_user_password }} lxc_container_template_main_apt_repo: "http://archive.ubuntu.com/ubuntu" lxc_container_template_security_apt_repo: "http://security.ubuntu.com/ubuntu" diff --git a/playbooks/roles/lxc_container_create/tasks/container_create.yml b/playbooks/roles/lxc_container_create/tasks/container_create.yml index bf2a4f7..efdbfc7 100644 --- a/playbooks/roles/lxc_container_create/tasks/container_create.yml +++ b/playbooks/roles/lxc_container_create/tasks/container_create.yml @@ -60,7 +60,7 @@ fs_size: "{{ lxc_container_fs_size }}" fs_type: "{{ lxc_container_fs_type }}" vg_name: "{{ lxc_container_vg_name }}" - template_options: "--release {{ properties.container_release|default(lxc_container_release) }}" + template_options: "{{ lxc_container_template_options }}" container_command: | mkdir -p ~/.ssh/ if [ ! -f "~/.ssh/authorized_keys" ];then @@ -91,6 +91,17 @@ tags: - lxc-container-create +- name: Force container user password set + lxc-container: + name: "{{ inventory_hostname }}" + container_command: | + if [ "$(getent passwd {{ lxc_container_user_name }})" ];then + echo "{{ lxc_container_user_name }}:{{ lxc_container_user_password }}" | chpasswd; + fi + delegate_to: "{{ physical_host }}" + tags: + - lxc-user-password-regen + - name: Container network interfaces lxc-container: name: "{{ inventory_hostname }}"