openstack.cloud.routers_info 模块 – 获取一个或多个 OpenStack 路由器信息。

注意

此模块是 openstack.cloud 集合 (版本 2.3.0) 的一部分。

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

要安装它,请使用: ansible-galaxy collection install openstack.cloud。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求

要在剧本中使用它,请指定: openstack.cloud.routers_info

概要

  • 从 OpenStack 获取一个或多个路由器的信息。

要求

在执行此模块的主机上需要以下要求。

  • python >= 3.6

  • openstacksdk >= 1.0.0

参数

参数

注释

api_timeout

整数

套接字层在 API 调用超时之前应等待多长时间。如果省略此参数,则不会将任何内容传递给 requests 库。

auth

字典

包含云的认证插件策略所需的认证信息的字典。对于默认的 *password* 插件,这将包含 *auth_url*、*username*、*password*、*project_name* 以及云支持的任何有关域的信息(例如,*user_domain_name* 或 *project_domain_name*)。对于其他插件,此参数需要包含该认证插件所需的任何参数。如果提供了命名云或存在 OpenStack OS_* 环境变量,则不需要此参数。

auth_type

字符串

要使用的认证插件的名称。如果云使用密码认证以外的其他认证方式,则应在此处指示插件的名称,并相应地更新 *auth* 参数的内容。

ca_cert

别名:cacert

字符串

CA 证书包的路径,可用作验证 SSL API 请求的一部分。

client_cert

别名:cert

字符串

客户端证书的路径,用作 SSL 事务的一部分。

client_key

别名:key

字符串

客户端密钥的路径,用作 SSL 事务的一部分。

cloud

任意类型

要操作的命名云或云配置。如果 *cloud* 是字符串,则它引用在 OpenStack clouds.yaml 文件中定义的命名云配置。为 *auth* 和 *auth_type* 提供默认值。如果提供了 *auth* 或存在 OpenStack OS_* 环境变量,则不需要此参数。如果 *cloud* 是字典,则它包含完整的云配置,就像 clouds.yaml 的一部分一样。

filters

字典

用于进一步过滤的元数据的字典。此字典的元素可能是其他字典。

默认值: {}

description

字符串

按资源的易于理解的描述过滤列表结果。

is_admin_state_up

布尔值

按资源的管理状态过滤列表结果,该状态为启动 (true) 或停止 (false)。

选项

  • false

  • true

name

字符串

按资源的易于理解的名称过滤列表结果。

project_id

别名:tenant_id

字符串

按拥有资源的项目的 ID 过滤列表结果。

revision_number

整数

按资源的修订号过滤列表结果。

tags

列表 / 元素=字符串

用于过滤列表结果的标签列表。将返回与此列表中所有标签匹配的资源。

interface

别名:endpoint_type

字符串

要从服务目录中获取的端点 URL 类型。

选项

  • "admin"

  • "internal"

  • "public" ← (默认)

name

字符串

路由器的名称或 ID

region_name

字符串

区域名称。

sdk_log_level

字符串

OpenStackSDK 的日志级别

选项

  • "INFO" ← (默认)

  • "DEBUG"

sdk_log_path

字符串

OpenStackSDK 日志文件的路径。如果为空,则不写入日志

timeout

整数

Ansible 应该等待请求的资源多长时间。

默认值: 180

validate_certs

别名:verify

布尔值

是否应验证 SSL API 请求。

在 Ansible 2.3 之前,默认为 true

选项

  • false

  • true

wait

布尔值

Ansible 是否应等到请求的资源完成。

选项

  • false

  • true ← (默认)

备注

注意

  • 可以使用标准的 OpenStack 环境变量(例如 OS_USERNAME),而不是提供显式值。

  • 身份验证信息由openstacksdk驱动,这意味着值可以来自`/etc/ansible/openstack.yaml`、`/etc/openstack/clouds.yaml`或`~/.config/openstack/clouds.yaml`中的yaml配置文件,然后来自标准环境变量,最后通过剧本中的显式参数获取。更多信息请访问https://docs.openstack.org/openstacksdk/

示例

- name: Gather information about routers
  openstack.cloud.routers_info:
    auth:
      auth_url: https://identity.example.com
      username: user
      password: password
      project_name: someproject
  register: result

- name: Show openstack routers
  debug:
    msg: "{{ result.routers }}"

- name: Gather information about a router by name
  openstack.cloud.routers_info:
    auth:
      auth_url: https://identity.example.com
      username: user
      password: password
      project_name: someproject
    name: router1
  register: result

- name: Show openstack routers
  debug:
    msg: "{{ result.routers }}"

- name: Gather information about a router with filter
  openstack.cloud.routers_info:
    auth:
      auth_url: https://identity.example.com
      username: user
      password: password
      project_name: someproject
    filters:
      is_admin_state_up: True
  register: result

- name: Show openstack routers
  debug:
    msg: "{{ result.routers }}"

- name: List all routers
  openstack.cloud.routers_info:
     cloud: devstack
  register: routers

- name: List ports of first router
  openstack.cloud.port_info:
    cloud: devstack
    filters:
      device_id: "{{ routers.routers.0.id }}"
  register: ports

- name: Show first router's fixed ips
  debug:
    msg: "{{ ports.ports
        |rejectattr('device_owner', 'equalto', 'network:router_gateway')
        |sum(attribute='fixed_ips', start=[])
        |map(attribute='ip_address')
        |sort|list }}"

- name: List ports of all routers
  loop: "{{ routers.routers }}"
  openstack.cloud.port_info:
    cloud: devstack
    filters:
      device_id: "{{ item['id'] }}"
  register: ports

- name: Transform ports for interfaces_info entries
  loop: "{{ ports.results|map(attribute='ports')|list }}"
  set_fact:
    interfaces_info: |-
        {% for port in item %}
        {% if port.device_owner != "network:router_gateway" %}
        {% for fixed_ip in port['fixed_ips'] %}
        - port_id: {{ port.id }}
          ip_address: {{ fixed_ip.ip_address }}
          subnet_id: {{ fixed_ip.subnet_id }}
        {% endfor %}
        {% endif %}
        {% endfor %}
  register: interfaces

- name: Combine router and interfaces_info entries
  loop: "{{
      routers.routers|zip(interfaces.results|map(attribute='ansible_facts'))|list
  }}"
  set_fact:
    # underscore prefix to prevent overwriting facts outside of loop
    _router: "{{
        item.0|combine({'interfaces_info': item.1.interfaces_info|from_yaml})
    }}"
  register: routers

- name: Remove set_fact artifacts from routers
  set_fact:
    routers: "{{ {
        'routers': routers.results|map(attribute='ansible_facts._router')|list
    } }}"

- debug: var=routers

返回值

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

描述

routers

列表 / 元素=字典

包含关于路由器的所有OpenStack信息

返回值:始终返回,但可能为空

availability_zone_hints

列表 / 元素=字符串

可用区提示

返回值:成功

availability_zones

列表 / 元素=字符串

可用区

返回值:成功

created_at

字符串

创建路由器的日期和时间

返回值:成功

description

字符串

路由器的描述说明

返回值:成功

external_gateway_info

字典

路由器的外部网关信息。

返回值:成功

flavor_id

字符串

路由器类型的ID

返回值:成功

id

字符串

唯一UUID。

返回值:成功

is_admin_state_up

布尔值

网络管理状态

返回值:成功

is_distributed

布尔值

指示分布式路由器。

返回值:成功

is_ha

布尔值

指示高可用性路由器。

返回值:成功

name

字符串

赋予路由器的名称。

返回值:成功

project_id

字符串

与该路由器关联的项目ID。

返回值:成功

revision_number

整数

修订号

返回值:成功

routes

列表 / 元素=字符串

L3路由器的额外路由配置。

返回值:成功

status

字符串

路由器状态。

返回值:成功

tags

列表 / 元素=字符串

标签列表

返回值:成功

tenant_id

字符串

所有者租户ID

返回值:成功

updated_at

字符串

路由器最后更新的日期

返回值:成功

作者

  • OpenStack Ansible SIG