How to create template VMs with ansible

Hi! I’ve just set up the ansible configuration. I’m looking in the official qubes ansible repo at the example file and I am not seeing any example that creates a templateVM.

Inside the seemingly older and deprecated demo repo they had a property called vmtype that property is not documented in the official repo and I have to conclude that it is outdated. (it also does not work, although my ansible playbook fails with a “key not found” for the given template name when trying)

I used the forum post as my installation guide, it might be that I’ve got an outdated ansible package, still the documentation does not show how to make template VMs.

So the question is: is it possible to create template VMs with ansible? If so how?

Wild guess: try class, it is used in qvm salt states and also is not documented: :smile:

Good suggestion. It did not work but it made it clear that the vmtype is indeed a correct property key but it does not seem to work to give a template that it should copy from. It results in

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'fedora-42-xfce'
fatal: [localhost]: FAILED! => {"changed": false, "msg": "'fedora-42-xfce'"}

Hrm seems like a bug, unless you need to do something else for cloning:

Have you tried using the command create instead of the state present?

p.s. nevermind it calls create in the present state

Works -

---
- hosts: local
  connection: local 
  tasks:
      - name: Create a tester template
        qubesos:
          guest: template-tester
          state: present
          vmtype: TemplateVM
          template: debian-13-minimal

1 Like

Good question/thread. I think we need more/better/easier/simpler
guides/writeups for creating qubes and templates with Ansible.

I figured out the original problem. Since I was using a mgmtvm for the ansible stuff I don’t think it has access to any of my old templates that I’ve installed through dom0. It only has access to VMs tagged with created-by-mgmtvm.

I used qvm-tags test-fedora-42-xfce add created-by-mgmtvm and ansible was then able to clone test-fedora-42-xfce.

Interestingly I am able to make app VMs based on templates not created by the mgmtvm so it seems it has some form of read access.

After the tagging a new error appeared. I couldn’t find anything on the forum after a brief search so I’ll post it here too. I’ve tested this with fedora-42-minimal, fedora-42-xfce and debian-12-xfce and they all experience the same problem of not being able to clone appmenus

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: qubesadmin.exc.QubesException: Failed to clone appmenus
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to clone appmenus"}
1 Like