equinix / ansible-collection-equinix

Ansible content to help automate the management of Equinix resources
https://deploy.equinix.com/labs/ansible-collection-equinix/
GNU General Public License v3.0
1 stars 1 forks source link

Can't use `next-available` hardware reservation in the metal_device module #224

Closed ctreatma closed 2 months ago

ctreatma commented 2 months ago
SUMMARY

According to the collection docs, users can specify next-available as the hardware-reservation-id to select an available reservation without having to specify a particular reservation's UUID.

In practice, this results in a 404 error.

ISSUE TYPE
COMPONENT NAME

metal_device

ANSIBLE VERSION
equinix.cloud v0.10.0
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
   - name: "Create a device using reserved hardware"
     equinix.cloud.metal_device:
         project_id: "my-project-uuid"
         state: "present"
         hostname: "reservation_test"
         operating_system: "ubuntu_22_04"
         plan: "m3.small.x86"
         metro: "sv"
         hardware_reservation_id: "next-available"
EXPECTED RESULTS

Based on the Ansible collection docs and the underlying Metal API feature, I expect the playbook above to provision a Metal device on an unused hardware reservation in my project.

ACTUAL RESULTS

The playbook fails with the below error output

Error in metal_device: (404)
Reason: Not Found
ctreatma commented 2 months ago

I'm guessing the 404 is happening because the metal_device [module attempts to fetch the hardware reservation by ID before it makes the request to create a device](https://github.com/equinix/ansible-collection-equinix/blob/520e67d02c6d149bc5cfc8589b8df86d5d8246a6/plugins/modules/metal_device.py#L768-L773:

if module.params.get("hardware_reservation_id"):
    hw_res = module.get_hardware_reservation()
    if hw_res["provisionable"] is False:
        module.fail_json(
            msg="Hardware reservation %s is not provisionable" % hw_res['id'] 
        )

The analogous metal_device resource in Terraform does not attempt to fetch the reservation. If the reservation is not provisionable, the request to create a device will fail anyway, so the metal_device Ansible module should allow that to happen rather than trying to validate the specified reservation directly.

github-actions[bot] commented 2 months ago

This issue has been resolved in version 0.10.1 :tada: