Search code examples
ansibleopenstackopenstack-nova

Choose compute node(hypervisor) for instance creation with ansible openstack.cloud.server module


I am looking to specify which compute node to reside on when creating an instance with Openstack ansible module openstack.cloud.server, Actually I want to ansiblealize the following command:

$ openstack server create --flavor g2 --image Ubuntu-20.04 --network public2 --security-group default --hypervisor-hostname compute3 --os-compute-api-version 2.74 test
# OR
$ openstack server create --flavor g2 --image Ubuntu-20.04 --network public2 --security-group default --host compute3 --os-compute-api-version 2.74 test

How I can pass --host or --hypervisor-hostname similar to Openstack CLI to openstack.cloud.server module in ansible???


Solution

  • Try to use meta.hostname define you hypervisor:

    - name: Create a new instance and attaches to a network and passes metadata to the instance
      openstack.cloud.server:
          ......
          meta:
            hostname: test1
    

    meta:

    A list of key value pairs that should be provided as a metadata to the new instance

    Another way, it could use availability_zone parameter to select hosts:

    - name: launch an instance in specific host
      openstack.cloud.server:
        ......
        availability_zone: nova:compute3001
    

    See also this example.