--- - hosts: localhost connection: local gather_facts: no tasks: - name: clone template vm command: VBoxManage clonevm centos7-template --mode all --name {{ newVmName }} --register - name: temp.start clone vm command: VBoxManage startvm {{ newVmName }} --type headless - name: add temp host to inventory (ram) add_host: hostname: "{{ newVmName }}.lan" - name: flush local dns cache command: systemd-resolve --flush-caches - name: wait for new vm to register/update dns hostname and come available shell: /ssd/VirtualBox\ VMs/wait-for-hostname-resolvable.sh centos7-template.lan 60 - name: wait for ssh@vm to be accessable wait_for: timeout: 90 sleep: 2 host: "centos7-template.lan" port: 22 - hosts: centos7-template.lan gather_facts: no remote_user: root tasks: - name: check connection again wait_for_connection: timeout: 60 - name: change vms hostname command: hostnamectl set-hostname "{{ newVmName }}.lan" - name: reboot vm reboot: - hosts: localhost gather_facts: no connection: local tasks: - name: flush local dns cache command: systemd-resolve --flush-caches - name: wait for new vm to register/update dns hostname and come available shell: /ssd/VirtualBox\ VMs/wait-for-hostname-resolvable.sh "{{ newVmName }}.lan" 60 - name: wait for ssh@vm to be accessable wait_for: timeout: 90 sleep: 2 host: "{{ newVmName }}.lan" port: 22 - hosts: "{{ newVmName }}.lan" gather_facts: no remote_user: root tasks: - name: show fqdn of new vm command: hostname -f