community.general.one_service 模块 – 部署和管理 OpenNebula 服务

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定:community.general.one_service

概要

  • 管理 OpenNebula 服务

参数

参数

注释

api_password

字符串

用于登录 OpenNebula OneFlow API 服务器的用户的密码。如果未设置,则使用 ONEFLOW_PASSWORD 环境变量的值。

api_url

字符串

OpenNebula OneFlow API 服务器的 URL。

建议使用 HTTPS,以便用户名/密码不会在网络上以未加密的方式传输。

如果未设置,则使用 ONEFLOW_URL 环境变量的值。

api_username

字符串

用于登录 OpenNebula OneFlow API 服务器的用户的名称。如果未设置,则使用 ONEFLOW_USERNAME 环境变量的值。

cardinality

整数

指定角色的虚拟机数量。

custom_attrs

字典

键/值自定义属性的字典,将在实例化新服务时使用。

默认值: {}

force

布尔值

强制使用新的基数,即使它超出限制。

选择

  • false ← (默认)

  • true

group_id

整数

将设置为服务组的组的 ID。

mode

字符串

以八进制格式设置服务实例的权限模式,例如 0600,表示所有者具有 usemanage 权限,组和其他人没有权限。

owner_id

整数

将设置为服务所有者的用户的 ID。

role

字符串

应更改基数的角色的名称。

service_id

整数

您要管理的服务的 ID。

service_name

字符串

您要管理的服务的名称。

state

字符串

present - 从 template_idtemplate_name 指定的模板实例化服务。

absent - 终止由 template_idtemplate_name 指定的服务实例。

选择

  • "present" ← (默认)

  • "absent"

template_id

整数

用于创建服务新实例的服务模板的 ID。

template_name

字符串

用于创建服务新实例的服务模板的名称。

unique

布尔值

设置 unique=true 将确保在从 template_idtemplate_name 指定的模板实例化服务时,只有一个服务实例以 service_name 设置的名称运行。请查看下面的示例。

选择

  • false ← (默认)

  • true

wait

布尔值

等待实例在部署后达到“正在运行”状态或在缩放后达到“冷却”状态。

选择

  • false ← (默认)

  • true

wait_timeout

整数

等待放弃前的时长,以秒为单位。

默认值: 300

属性

属性

支持

描述

check_mode

支持: 完整

可以在 check_mode 中运行并返回更改状态预测,而无需修改目标。

diff_mode

支持:

在 diff 模式下,当处于 check_mode 时,将返回已更改(或可能需要更改)的详细信息。

示例

- name: Instantiate a new service
  community.general.one_service:
    template_id: 90
  register: result

- name: Print service properties
  ansible.builtin.debug:
    msg: result

- name: Instantiate a new service with specified service_name, service group and mode
  community.general.one_service:
    template_name: 'app1_template'
    service_name: 'app1'
    group_id: 1
    mode: '660'

- name: Instantiate a new service with template_id and pass custom_attrs dict
  community.general.one_service:
    template_id: 90
    custom_attrs:
      public_network_id: 21
      private_network_id: 26

- name: Instantiate a new service 'foo' if the service doesn't already exist, otherwise do nothing
  community.general.one_service:
    template_id: 53
    service_name: 'foo'
    unique: true

- name: Delete a service by ID
  community.general.one_service:
    service_id: 153
    state: absent

- name: Get service info
  community.general.one_service:
    service_id: 153
  register: service_info

- name: Change service owner, group and mode
  community.general.one_service:
    service_name: 'app2'
    owner_id: 34
    group_id: 113
    mode: '600'

- name: Instantiate service and wait for it to become RUNNING
  community.general.one_service:
    template_id: 43
    service_name: 'foo1'

- name: Wait service to become RUNNING
  community.general.one_service:
    service_id: 112
    wait: true

- name: Change role cardinality
  community.general.one_service:
    service_id: 153
    role: bar
    cardinality: 5

- name: Change role cardinality and wait for it to be applied
  community.general.one_service:
    service_id: 112
    role: foo
    cardinality: 7
    wait: true

返回值

常见的返回值记录在此处,以下是此模块独有的字段

描述

group_id

整数

服务组 ID

返回: 成功

示例: 1

group_name

字符串

服务的组名

返回: 成功

示例: "one-users"

mode

整数

服务模式

返回: 成功

示例: 660

owner_id

整数

服务的所有者ID

返回: 成功

示例: 143

owner_name

字符串

服务的所有者名称

返回: 成功

示例: "ansible-test"

roles

列表 / 元素=字符串

角色字典列表,每个角色由名称、基数、状态和节点ID描述

返回: 成功

示例: [{"cardinality": 1, "ids": [123, 456], "name": "foo", "state": "RUNNING"}, {"cardinality": 2, "ids": [452, 567, 746], "name": "bar", "state": "RUNNING"}]

service_id

整数

服务 ID

返回: 成功

示例: 153

service_name

字符串

服务名称

返回: 成功

示例: "app1"

state

字符串

服务实例的状态

返回: 成功

示例: "RUNNING"

作者

  • Milan Ilic (@ilicmilan)