如何在Ansible的openstack.cloud.server模块中指定计算节点创建实例?
在Ansible的openstack.cloud.server模块中指定计算节点
要将你提供的OpenStack CLI命令转换为Ansible实现,openstack.cloud.server模块提供了直接对应--host和--hypervisor-hostname的参数,同时支持指定计算API版本,以下是具体实现:
方法1:使用host参数对应CLI的--host
- name: 创建指定计算节点的OpenStack实例 openstack.cloud.server: name: test flavor: g2 image: Ubuntu-20.04 network: public2 security_groups: - default host: compute3 api_version: compute: 2.74 state: present
方法2:使用scheduler_hints对应CLI的--hypervisor-hostname
- name: 创建指定计算节点的OpenStack实例 openstack.cloud.server: name: test flavor: g2 image: Ubuntu-20.04 network: public2 security_groups: - default scheduler_hints: hypervisor_hostname: compute3 api_version: compute: 2.74 state: present
参数说明
host:直接指定实例要部署的计算节点主机名,和CLI的--host作用完全一致。scheduler_hints.hypervisor_hostname:通过OpenStack调度器提示指定宿主机,对应CLI的--hypervisor-hostname选项。api_version.compute:设置计算服务的API版本,对应CLI的--os-compute-api-version 2.74参数。
注意事项
- 执行任务的账号需要具备足够权限(通常是管理员权限)才能指定计算节点。
- 确认目标计算节点
compute3状态正常且有足够资源承载该实例。
内容的提问来源于stack exchange,提问作者YosSaL
相关产品推荐
相关产品推荐

