Theforeman.foreman cannot create vm: vmid is required

Problem:
Using the Ansible collection theforeman.foreman (current v2.2) it’s not possible to create a VM via Foreman (3.0.0-rc2) using Proxmox (v6.4).

The error message is: “vmid is required for this operation”.

There is no vmid which could be passed as parameter, so the plugin foreman-fog-proxmox (v 0.14) might not get the next free vmid from Proxmox.

There is a quite old bug similar to this: https://github.com/theforeman/foreman_fog_proxmox/issues/83

It looks like the foreman-fog-proxmox does not get the next free vmid from Proxmox.

Is this a known issue?

Kind regards,
Anhu

Foreman and Proxy versions:

foreman                         3.0.0~rc2-1
foreman-assets                  3.0.0~rc2-1
foreman-cli                     3.0.0~rc2-1
foreman-debug                   3.0.0~rc2-1
foreman-dynflow-sidekiq         3.0.0~rc2-1
foreman-installer               3.0.0~rc2-1
foreman-postgresql              3.0.0~rc2-1
foreman-proxy                   3.0.0~rc2-1
foreman-service                 3.0.0~rc2-1
ruby-foreman-ansible            9999-plugin+scratchbuild+20210716145329
ruby-foreman-deface             1.5.3-1
ruby-foreman-fog-proxmox        0.14 (manually installed!)
ruby-foreman-puppet             1.0.0~rc2-1
ruby-foreman-remote-execution   9999-plugin+scratchbuild+20210715153232
ruby-foreman-tasks              5.0.0-1
ruby-foreman-tasks-core         0.4.0-1
ruby-foreman-templates          9.0.0-1
ruby-hammer-cli-foreman         3.0.0-1
ruby-hammer-cli-foreman-puppet  0.0.3-2

Distribution and version:
Debian 10

Other relevant data:
(with some data protection values aka my…)

The full traceback is:
  File "/tmp/ansible_theforeman.foreman.host_payload_ie_6hlex/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 1190, in resource_action                                      
    result = self._resource_call(resource, action, resource_payload, options=options, data=data, files=files)
  File "/tmp/ansible_theforeman.foreman.host_payload_ie_6hlex/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 674, in _resource_call                                        
    return self._resource(resource).call(*args, **kwargs)
  File "/tmp/ansible_theforeman.foreman.host_payload_ie_6hlex/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 864, in call                                                         
    return self.api.call(self.name, action, params, headers, options, data, files)
  File "/tmp/ansible_theforeman.foreman.host_payload_ie_6hlex/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 482, in call                                                         
    return self._call_action(action, params, headers, data, files)
  File "/tmp/ansible_theforeman.foreman.host_payload_ie_6hlex/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 494, in _call_action                                                 
    headers, data, files)
  File "/tmp/ansible_theforeman.foreman.host_payload_ie_6hlex/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 532, in http_call                                                    
    request.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
fatal: [myforeman]: FAILED! => {
    "changed": false,
    "error": {
        "errors": {
            "base": [
                "Failed to create a compute My-Proxmox (Proxmox) instance host01.mydomain: vmid is required for this operation\n "
            ]
        },
        "full_messages": [
            "Failed to create a compute My-Proxmox (Proxmox) instance host01.mydomain: vmid is required for this operation\n "
        ],
        "id": null
    },
    "invocation": {
        "module_args": {
            "activation_keys": null,
            "architecture": null,
            "build": true,
            "comment": null,
            "compute_attributes": null,
            "compute_profile": null,
            "compute_resource": null,
            "config_groups": null,
            "content_source": null,
            "content_view": null,
            "domain": null,
            "enabled": null,
            "environment": null,
            "hostgroup": "myhostgroup01",
            "image": null,
            "interfaces_attributes": null,
            "ip": null,
            "kickstart_repository": null,
            "lifecycle_environment": null,
            "location": "Myplace",
            "mac": null,
            "managed": null,
            "medium": null,
            "name": "host01.mydomain",
            "openscap_proxy": null,
            "operatingsystem": null,
            "organization": "My Organization",
            "owner": null,
            "owner_group": null,
            "parameters": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "provision_method": null,
            "ptable": null,
            "puppet_ca_proxy": null,
            "puppet_proxy": null,
            "puppetclasses": null,
            "pxe_loader": null,
            "realm": null,
            "root_pass": null,
            "server_url": "https://myforemanhost.mydomain",
            "state": "present",
            "subnet": null,
            "subnet6": null,
            "username": "ansible",
            "validate_certs": false
        }
    },
    "msg": "Error while performing create on hosts: 422 Client Error: Unprocessable Entity for url: https://myforemanhost.mydomain/api/hosts"
}

P.S.

Playbook:

---
- name: Rollout new hosts
  gather_facts: yes
  hosts:
    - myforemanhost
  roles:
    - rollout_hosts

Role task/main.yml:

---   
# tasks file for rollout_hosts
#

- name: "Create a host"
  theforeman.foreman.host:
    username: "ansible"
    password: "changeme"
    server_url: "https://myforemanhost.mydomain"
    validate_certs: false
    name: "somehost01.mydomain"
    build: true
    hostgroup: test01
    organization: "My Organization"
    location: "Mylocation"
    state: present

You could try passing an vmid in compute_attributes, like this:

- name: create a host
  theforeman.foreman.host:
    name: somehost
    …
    compute_attributes:
      vmid: THE_ID

but no idea if that helps… I would have expected it to generate an ID for you too.

@tristanrobert might have an idea, as he is the author of the plugin :wink:

2 Likes

Great, that avoids the corresponding error message (if vmid is a string). The VM was created but unfortunately did not automatically “start after creation” (which is another parameter in the GUI). I tried as well a corresponding parameter (guessed):

compute_atributes:
  vmid: "777"
  start_after_creation: true

but that did not work.

This is the (-vvv) result of the command:

changed: [myforemanhost] => {
    "changed": true,
    "diff": {
        "after": {
            "hosts": [
                {
                    "architecture_id": 1,
                    "build": true,
                    "compute_profile_id": 1,
                    "compute_resource_id": 1,
                    "config_group_ids": [],
                    "domain_id": 1,
                    "enabled": true,
                    "environment_id": 1,
                    "host_parameters_attributes": [],
                    "hostgroup_id": 1,
                    "id": 19,
                    "ip": "10.11.12.13",
                    "location_id": 2,
                    "managed": true,
                    "medium_id": 4,
                    "name": "somehost01.mydomain",
                    "operatingsystem_id": 2,
                    "organization_id": 1,
                    "owner_id": 8,
                    "owner_type": "User",
                    "provision_method": "build",
                    "ptable_id": 171,
                    "puppet_ca_proxy_id": 1,
                    "puppet_proxy_id": 1,
                    "puppetclass_ids": [],
                    "pxe_loader": "PXELinux BIOS",
                    "subnet_id": 1
                }
            ]
        },
        "before": {
            "hosts": [
                {}
            ]
        }
    },
    "entity": {
        "hosts": [
            {
                "all_parameters": [
                    ...
                ],
                "all_puppetclasses": [],
                "architecture_id": 1,
                "architecture_name": "x86_64",
                "bmc_available": false,
                "build": true,
                "build_status": 1,
                "build_status_label": "Pending installation",
                "capabilities": [
                    "build",
                    "new_volume",
                    "new_interface",
                    "image"
                ],
                "certname": "somehost01.mydomain",
                "comment": null,
                "compute_profile_id": 1,
                "compute_profile_name": "1-Small",
                "compute_resource_id": 1,
                "compute_resource_name": "MyProxmox",
                "config_groups": [],
                "configuration_status": 0,
                "configuration_status_label": "No reports",
                "created_at": "2021-09-07T09:39:03.321Z",
                "disk": null,
                "domain_id": 1,
                "domain_name": "mydomain",
                "enabled": true,
                "environment_id": 1,
                "environment_name": "production",
                "global_status": 0,
                "global_status_label": "Warning",
                "hostgroup_id": 1,
                "hostgroup_name": "test01",
                "hostgroup_title": "test01",
                "id": 19,
                "image_file": "",
                "image_id": null,
                "image_name": null,
                "installed_at": null,
                "interfaces": [
                    {
                        "created_at": "2021-09-07T09:39:03.332Z",
                        "domain_id": 1,
                        "domain_name": "mydomain",
                        "execution": true,
                        "fqdn": "somehost01.mydomain",
                        "id": 19,
                        "identifier": null,
                        "ip": "10.11.12.13",
                        "ip6": null,
                        "mac": null,
                        "managed": true,
                        "mtu": 1500,
                        "name": "somehost01.mydomain",
                        "primary": true,
                        "provision": true,
                        "subnet6_id": null,
                        "subnet6_name": null,
                        "subnet_id": 1,
                        "subnet_name": "mysubnet",
                        "type": "interface",
                        "updated_at": "2021-09-07T09:39:03.332Z",
                        "virtual": false
                    }
                ],
                "ip": "10.11.12.13",
                "ip6": null,
                "last_compile": null,
                "last_report": null,
                "location_id": 2,
                "location_name": "MyLocation",
                "mac": null,
                "managed": true,
                "medium_id": 4,
                "medium_name": "Debian mirror",
                "model_id": null,
                "model_name": null,
                "name": "somehost01.mydomain",
                "operatingsystem_id": 2,
                "operatingsystem_name": "Debian 11",
                "organization_id": 1,
                "organization_name": "MyOrganization",
                "owner_id": 8,
                "owner_name": " Ansible",
                "owner_type": "User",
                "parameters": [],
                "permissions": {
                    "build_hosts": true,
                    "cockpit_hosts": true,
                    "console_hosts": true,
                    "create_hosts": true,
                    "destroy_hosts": true,
                    "edit_hosts": true,
                    "forget_status_hosts": true,
                    "ipmi_boot_hosts": true,
                    "play_roles_on_host": true,
                    "power_hosts": true,
                    "view_hosts": true
                },
                "provision_method": "build",
                "ptable_id": 171,
                "ptable_name": "Preseed LVM MyOrganization",
                "puppet": {
                    "all_puppetclasses": [],
                    "config_groups": [],
                    "puppetclasses": []
                },
                "puppet_ca_proxy": {
                    "id": 1,
                    "name": "MyForeman.mydomain",
                    "url": "https://myforemanhost.mydomain:8443"
                },
                "puppet_ca_proxy_id": 1,
                "puppet_ca_proxy_name": "myforemanhost.mydomain",
                "puppet_proxy": {
                    "id": 1,
                    "name": "myforemanhost.mydomain",
                    "url": "https://myforemanhost.mydomain:8443"
                },
                "puppet_proxy_id": 1,
                "puppet_proxy_name": "myforemanhost.mydomain",
                "puppet_status": 0,
                "puppetclasses": [],
                "pxe_loader": "PXELinux BIOS",
                "realm_id": null,
                "realm_name": null,
                "sp_ip": null,
                "sp_mac": null,
                "sp_name": null,
                "sp_subnet_id": null,
                "subnet6_id": null,
                "subnet6_name": null,
                "subnet_id": 1,
                "subnet_name": "MySubnet",
                "token": "d1.....",
                "updated_at": "2021-09-07T09:39:03.321Z",
                "uptime_seconds": null,
                "use_image": null,
                "uuid": null
            }
        ]
    },
    "invocation": {
        "module_args": {
            "activation_keys": null,
            "architecture": null,
            "build": true,
            "comment": null,
            "compute_attributes": {
                "start_after_creation": true,
                "vmid": "777"
            },
            "compute_profile": null,
            "compute_resource": null,
            "config_groups": null,
            "content_source": null,
            "content_view": null,
            "domain": null,
            "enabled": null,
            "environment": null,
            "hostgroup": "test01",
            "image": null,
            "interfaces_attributes": null,
            "ip": null,
            "kickstart_repository": null,
            "lifecycle_environment": null,
            "location": "MyLocation",
            "mac": null,
            "managed": null,
            "medium": null,
            "name": "somehost01.mydomain",
            "openscap_proxy": null,
            "operatingsystem": null,
            "organization": "MyOrganization",
            "owner": null,
            "owner_group": null,
            "parameters": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "provision_method": null,
            "ptable": null,
            "puppet_ca_proxy": null,
            "puppet_proxy": null,
            "puppetclasses": null,
            "pxe_loader": null,
            "realm": null,
            "root_pass": null,
            "server_url": "https://myforemanhost.mydomain",
            "state": "present",
            "subnet": null,
            "subnet6": null,
            "username": "ansible",
            "validate_certs": false
        }
    }
}

I know that for VMware, we need to pass start: "1", like this:

    compute_attributes:
      start: "1"

Might be worth trying? Last time I came close to a Proxmox installation was 2014, so I am purely guessing here :wink:

1 Like

Mhh, looking at the code of foreman_fog_proxmox, try start_after_create: "1"

Maybe start_after_create: true would also work, not 100% sure.

Perfect, “start: 1” works!

Since the (next available free) vmid should still be given by Proxmox, I should not close this ticket yet. @tristanrobert : any sugestions? Could I help to get this fully working again? I had/have a 2.4-devel version running quite fine, that broke at some time.

works as well. Might be even better than start: 1. I should have had a glimps at the code by myself. Sry.

1 Like