community.general.one_vm 模块 – 创建或终止 OpenNebula 实例
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.general。您需要进一步的要求才能使用此模块,请参阅 要求 以了解详细信息。
要在 playbook 中使用它,请指定: community.general.one_vm。
概要
- 管理 OpenNebula 实例 
要求
执行此模块的主机需要以下要求。
- pyone 
参数
| 参数 | 注释 | 
|---|---|
| 用于登录 OpenNebula RPC 服务器的用户的密码。如果未设置,则使用  设置环境变量  | |
| 用于登录 OpenNebula RPC 服务器的用户的名称。如果未设置,则使用  | |
| 要添加到新实例或用于设置具有这些属性的实例的  键不区分大小写,OpenNebula 会自动将其转换为大写。 请注意, 可以将  例如:“ 当与  默认值:  | |
| 要启动的实例数 默认值:  | |
| 键/值属性的字典,只能与  | |
| 标签列表,只能与  | |
| 新实例所需的 CPU 百分比除以 100。半个处理器写为 0.5。 | |
| 用于创建新实例的数据存储的名称 | |
| 用于创建新实例的数据存储的名称 | |
| 从 VM 磁盘创建映像。 它是一个字典,您必须在其中指定新映像的  (可选)您可以指定要保存的磁盘的  注意: 此操作仅在第一个 VM 上执行(如果传递了多个 VM ID),并且该 VM 必须处于  如果具有指定的  | |
| 为新实例创建的磁盘大小(以 MB、GB、TB 等为单位)。 注意: 如果模板包含多个磁盘,则大小的顺序与  | |
| 指示应部署多少个与  注意: ID 最小的实例将首先被终止。 | |
| 将设置为实例组的组的 ID | |
| 硬性重启、关闭或终止实例  选项 
 | |
| 用于以下状态的实例 ID 列表: | |
| 要与新实例关联的标签列表,或用于设置具有这些标签的实例的  默认值:  | |
| 新实例的内存大小(以 MB、GB 等为单位) | |
| 以八进制格式设置实例的权限模式,例如  | |
| 包含网络参数的字典列表。有关更多详细信息,请参见示例。 默认值:  | |
| 将设置为实例所有者的用户的 ID | |
| 创建模板的私有持久副本以及在 DISK 中定义的任何映像,并实例化该副本。 选项 
 | |
| 
 
 
 
 
 选项 
 | |
| 用于创建新实例的 VM 模板的 ID | |
| 用于创建新实例的 VM 模板的名称 | |
| 当提供  当创建新 VM 时,通过直接模板合并模拟  允许完全修改  | |
| 新 VM 将拥有的 CPU(核心)数量。 | |
| 设置为 true 以在创建时将 VM 置于保持状态 选项 
 | |
| 等待实例达到其所需状态后才返回。请记住,如果您正在等待实例处于运行状态,这并不意味着您将能够通过 SSH 连接到该计算机,只是意味着该实例上的启动过程已经开始,有关详细信息,请参见“wait_for”示例。 选项 
 | |
| 等待放弃之前的时间,以秒为单位 默认值:  | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持: 完整 | 可以在  | |
| 支持: 无 | 在差异模式下,将返回已更改的内容的详细信息(或者可能需要在  | 
示例
- name: Create a new instance
  community.general.one_vm:
    template_id: 90
  register: result
- name: Print VM properties
  ansible.builtin.debug:
    msg: result
- name: Deploy a new VM on hold
  community.general.one_vm:
    template_name: 'app1_template'
    vm_start_on_hold: 'True'
- name: Deploy a new VM and set its name to 'foo'
  community.general.one_vm:
    template_name: 'app1_template'
    attributes:
      name: foo
- name: Deploy a new VM and set its group_id and mode
  community.general.one_vm:
    template_id: 90
    group_id: 16
    mode: 660
- name: Deploy a new VM  as persistent
  community.general.one_vm:
    template_id: 90
    persistent: true
- name: Change VM's permissions to 640
  community.general.one_vm:
    instance_ids: 5
    mode: 640
- name: Deploy 2 new instances and set memory, vcpu, disk_size and 3 networks
  community.general.one_vm:
    template_id: 15
    disk_size: 35.2 GB
    memory: 4 GB
    vcpu: 4
    count: 2
    networks:
      - NETWORK_ID: 27
      - NETWORK: "default-network"
        NETWORK_UNAME: "app-user"
        SECURITY_GROUPS: "120,124"
      - NETWORK_ID: 27
        SECURITY_GROUPS: "10"
- name: Deploy a new instance which uses a Template with two Disks
  community.general.one_vm:
    template_id: 42
    disk_size:
      - 35.2 GB
      - 50 GB
    memory: 4 GB
    vcpu: 4
    count: 1
    networks:
      - NETWORK_ID: 27
- name: "Deploy an new instance with attribute 'bar: bar1' and set its name to 'foo'"
  community.general.one_vm:
    template_id: 53
    attributes:
      name: foo
      bar: bar1
- name: "Enforce that 2 instances with attributes 'foo1: app1' and 'foo2: app2' are deployed"
  community.general.one_vm:
    template_id: 53
    attributes:
      foo1: app1
      foo2: app2
    exact_count: 2
    count_attributes:
      foo1: app1
      foo2: app2
- name: Enforce that 4 instances with an attribute 'bar' are deployed
  community.general.one_vm:
    template_id: 53
    attributes:
      name: app
      bar: bar2
    exact_count: 4
    count_attributes:
      bar:
# Deploy 2 new instances with attribute 'foo: bar' and labels 'app1' and 'app2' and names in format 'fooapp-##'
# Names will be: fooapp-00 and fooapp-01
- name: Deploy 2 new instances
  community.general.one_vm:
    template_id: 53
    attributes:
      name: fooapp-##
      foo: bar
    labels:
      - app1
      - app2
    count: 2
# Deploy 2 new instances with attribute 'app: app1' and names in format 'fooapp-###'
# Names will be: fooapp-002 and fooapp-003
- name: Deploy 2 new instances
  community.general.one_vm:
    template_id: 53
    attributes:
      name: fooapp-###
      app: app1
    count: 2
# Reboot all instances with name in format 'fooapp-#'
# Instances 'fooapp-00', 'fooapp-01', 'fooapp-002' and 'fooapp-003' will be rebooted
- name: Reboot all instances with names in a certain format
  community.general.one_vm:
    attributes:
      name: fooapp-#
    state: rebooted
# Enforce that only 1 instance with name in format 'fooapp-#' is deployed
# The task will delete oldest instances, so only the 'fooapp-003' will remain
- name: Enforce that only 1 instance with name in a certain format is deployed
  community.general.one_vm:
    template_id: 53
    exact_count: 1
    count_attributes:
      name: fooapp-#
- name: Deploy an new instance with a network
  community.general.one_vm:
    template_id: 53
    networks:
      - NETWORK_ID: 27
  register: vm
- name: Wait for SSH to come up
  ansible.builtin.wait_for_connection:
  delegate_to: '{{ vm.instances[0].networks[0].ip }}'
- name: Terminate VMs by ids
  community.general.one_vm:
    instance_ids:
      - 153
      - 160
    state: absent
- name: Reboot all VMs that have labels 'foo' and 'app1'
  community.general.one_vm:
    labels:
      - foo
      - app1
    state: rebooted
- name: "Fetch all VMs that have name 'foo' and attribute 'app: bar'"
  community.general.one_vm:
    attributes:
      name: foo
      app: bar
  register: results
- name: Deploy 2 new instances with labels 'foo1' and 'foo2'
  community.general.one_vm:
    template_name: app_template
    labels:
      - foo1
      - foo2
    count: 2
- name: Enforce that only 1 instance with label 'foo1' will be running
  community.general.one_vm:
    template_name: app_template
    labels:
      - foo1
    exact_count: 1
    count_labels:
      - foo1
- name: Terminate all instances that have attribute foo
  community.general.one_vm:
    template_id: 53
    exact_count: 0
    count_attributes:
      foo:
- name: "Power-off the VM and save VM's disk with id=0 to the image with name 'foo-image'"
  community.general.one_vm:
    instance_ids: 351
    state: poweredoff
    disk_saveas:
      name: foo-image
- name: "Save VM's disk with id=1 to the image with name 'bar-image'"
  community.general.one_vm:
    instance_ids: 351
    disk_saveas:
      name: bar-image
      disk_id: 1
- name: "Deploy 2 new instances with a custom 'start script'"
  community.general.one_vm:
    template_name: app_template
    count: 2
    updateconf:
      CONTEXT:
        START_SCRIPT: ip r r 169.254.16.86/32 dev eth0
- name: "Add a custom 'start script' to a running VM"
  community.general.one_vm:
    instance_ids: 351
    updateconf:
      CONTEXT:
        START_SCRIPT: ip r r 169.254.16.86/32 dev eth0
- name: "Update SSH public keys inside the VM's context"
  community.general.one_vm:
    instance_ids: 351
    updateconf:
      CONTEXT:
        SSH_PUBLIC_KEY: |-
          ssh-rsa ...
          ssh-ed25519 ...
返回值
常见返回值记录在 此处,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 已更改状态或使用  返回: 成功 | |
| 与实例关联的键/值属性的字典 返回: 成功 示例:  | |
| CPU 百分比除以 100 返回: 成功 示例:  | |
| 磁盘大小(以 MB 为单位) 返回: 成功 示例:  | |
| VM 的组 ID 返回: 成功 示例:  | |
| VM 的组名称 返回: 成功 示例:  | |
| 与实例关联的字符串标签列表 返回: 成功 示例:  | |
| 实例的 lcm 状态,仅在状态为 ACTIVE 时相关 返回: 成功 示例:  | |
| 内存大小(以 MB 为单位) 返回: 成功 示例:  | |
| VM 的模式 返回: 成功 示例:  | |
| 包含每个 NIC 的 IP、名称、MAC、SECURITY_GROUPS 信息的字典列表 返回: 成功 示例:  | |
| VM 的所有者 ID 返回: 成功 示例:  | |
| VM 的所有者名称 返回: 成功 示例:  | |
| 实例的状态 返回: 成功 示例:  | |
| VM 的模板 ID 返回: 成功 示例:  | |
| 使用 updateconf API 调用设置的键/值属性的字典。 返回: 成功 示例:  | |
| 实例的运行时间(以小时为单位) 返回: 成功 示例:  | |
| CPU(核心)数量 返回: 成功 示例:  | |
| VM ID 返回: 成功 示例:  | |
| VM 名称 返回: 成功 示例:  | |
| 基于使用  labels that are specified with  选项。 返回: 成功 | |
| 与实例关联的键/值属性的字典 返回: 成功 示例:  | |
| CPU 百分比除以 100 返回: 成功 示例:  | |
| 磁盘大小(以 MB 为单位) 返回: 成功 示例:  | |
| VM 的组 ID 返回: 成功 示例:  | |
| VM 的组名称 返回: 成功 示例:  | |
| 与实例关联的字符串标签列表 返回: 成功 示例:  | |
| 实例的 lcm 状态,仅在状态为 ACTIVE 时相关 返回: 成功 示例:  | |
| 内存大小(以 MB 为单位) 返回: 成功 示例:  | |
| VM 的模式 返回: 成功 示例:  | |
| 包含每个 NIC 的 IP、名称、MAC、SECURITY_GROUPS 信息的字典列表 返回: 成功 示例:  | |
| VM 的用户 ID 返回: 成功 示例:  | |
| VM 的用户名 返回: 成功 示例:  | |
| 实例的状态 返回: 成功 示例:  | |
| VM 的模板 ID 返回: 成功 示例:  | |
| 使用 updateconf API 调用设置的键/值属性的字典 返回: 成功 示例:  | |
| 实例的运行时间(以小时为单位) 返回: 成功 示例:  | |
| CPU(核心)数量 返回: 成功 示例:  | |
| VM ID 返回: 成功 示例:  | |
| VM 名称 返回: 成功 示例:  | 
