diff --git a/ansible-kvm-vms/playbooks/create_vms.yml b/ansible-kvm-vms/playbooks/create_vms.yml index 751e717..3f4e8b7 100644 --- a/ansible-kvm-vms/playbooks/create_vms.yml +++ b/ansible-kvm-vms/playbooks/create_vms.yml @@ -9,14 +9,6 @@ - kvm_host_setup tasks: - - name: Provision each VM - include_role: - name: os_config - vars: - vm_name: "{{ item.name }}" - os_type: "{{ item.os_type }}" - loop: "{{ vms }}" - - name: Launch each VM include_role: name: vm_provision @@ -28,3 +20,4 @@ ram: "{{ item.ram }}" disk: "{{ item.disk }}" loop: "{{ vms }}" + diff --git a/ansible-kvm-vms/roles/vm_provision/tasks/main.yml b/ansible-kvm-vms/roles/vm_provision/tasks/main.yml index dc9b480..5828939 100644 --- a/ansible-kvm-vms/roles/vm_provision/tasks/main.yml +++ b/ansible-kvm-vms/roles/vm_provision/tasks/main.yml @@ -41,6 +41,18 @@ args: creates: "{{ vm_images_dir }}/{{ vm_name }}.qcow2" +- name: Customize VM image (Inject User/SSH/Sudo) + shell: | + virt-customize -a {{ vm_images_dir }}/{{ vm_name }}.qcow2 \ + --username {{ vm_user }} \ + --password {{ vm_password }} \ + --ssh-insert {{ vm_user }}:keys={{ vm_ssh_public_key | replace('~', lookup('env', 'HOME')) }} \ + --run-command "usermod -aG wheel {{ vm_user }}" && \ + touch {{ vm_images_dir }}/{{ vm_name }}.customized + become: yes + args: + creates: "{{ vm_images_dir }}/{{ vm_name }}.customized" + - name: Provision VM using virt-install shell: | virt-install \ @@ -53,14 +65,7 @@ --network network=default \ --graphics none \ --noautoconsole \ - --boot uefi \ - --cloud-init user-data=/tmp/{{ vm_name }}_user-data - args: + --boot uefi args: creates: "/etc/libvirt/qemu/{{ vm_name }}.xml" - -- name: Attach configuration to VM - debug: - msg: "Configuration is now handled by virt-install --cloud-init flag." - when: false # This task is now obsolete become: yes