Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxmox_kvm: support for tpmstate0 parameter #6533

Merged
merged 19 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/6533-proxmox_kvm-tpmstate0-support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- proxmox_kvm - added support for ``tpmstate0`` parameter to configure TPM (Trusted Platform Module) disk. TPM is required for Windows 11 installations (https://github.com/ansible-collections/community.general/pull/6533).
35 changes: 34 additions & 1 deletion plugins/modules/proxmox_kvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,24 @@
- Timeout for operations.
type: int
default: 30
tpmstate0:
description:
- A hash/dictionary of options for the Trusted Platform Module disk.
- A TPM state disk is required for Windows 11 installations.
suboptions:
storage:
description:
- O(tpmstate0.storage) is the storage identifier where to create the disk.
type: str
required: true
version:
description:
- The TPM version to use.
type: str
choices: ['1.2', '2.0']
default: '2.0'
type: dict
version_added: 7.1.0
update:
description:
- If C(true), the VM will be updated with new value.
Expand Down Expand Up @@ -938,7 +956,7 @@ def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update
urlencoded_ssh_keys = quote(kwargs['sshkeys'], safe='')
kwargs['sshkeys'] = str(urlencoded_ssh_keys)

# If update, don't update disk (virtio, efidisk0, ide, sata, scsi) and network interface
# If update, don't update disk (virtio, efidisk0, tpmstate0, ide, sata, scsi) and network interface
# pool parameter not supported by qemu/<vmid>/config endpoint on "update" (PVE 6.2) - only with "create"
if update:
if 'virtio' in kwargs:
Expand All @@ -951,6 +969,8 @@ def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update
del kwargs['ide']
if 'efidisk0' in kwargs:
del kwargs['efidisk0']
if 'tpmstate0' in kwargs:
del kwargs['tpmstate0']
if 'net' in kwargs:
del kwargs['net']
if 'force' in kwargs:
Expand Down Expand Up @@ -978,6 +998,13 @@ def create_vm(self, vmid, newid, node, name, memory, cpu, cores, sockets, update
if 'storage' != k])
kwargs['efidisk0'] = efidisk0_str

# Flatten tpmstate0 option to a string so that it's a string which is what Proxmoxer and the API expect
if 'tpmstate0' in kwargs:
kwargs['tpmstate0'] = '{storage}:1,version=v{version}'.format(
storage=kwargs['tpmstate0'].get('storage'),
version=kwargs['tpmstate0'].get('version')
)

# Convert all dict in kwargs to elements.
# For hostpci[n], ide[n], net[n], numa[n], parallel[n], sata[n], scsi[n], serial[n], virtio[n], ipconfig[n]
for k in list(kwargs.keys()):
Expand Down Expand Up @@ -1163,6 +1190,11 @@ def main():
tdf=dict(type='bool'),
template=dict(type='bool'),
timeout=dict(type='int', default=30),
tpmstate0=dict(type='dict',
options=dict(
storage=dict(type='str', required=True),
version=dict(type='str', choices=['2.0', '1.2'], default='2.0')
)),
update=dict(type='bool', default=False),
vcpus=dict(type='int'),
vga=dict(choices=['std', 'cirrus', 'vmware', 'qxl', 'serial0', 'serial1', 'serial2', 'serial3', 'qxl2', 'qxl3', 'qxl4']),
Expand Down Expand Up @@ -1356,6 +1388,7 @@ def main():
target=module.params['target'],
tdf=module.params['tdf'],
template=module.params['template'],
tpmstate0=module.params['tpmstate0'],
vcpus=module.params['vcpus'],
vga=module.params['vga'],
virtio=module.params['virtio'],
Expand Down