openstack.cloud.security_group 模块 – 管理 OpenStack 云的 Neutron 安全组。

注意

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

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

要安装它,请使用:ansible-galaxy collection install openstack.cloud。您需要进一步的要求才能使用此模块,请参阅 要求 以了解详细信息。

要在 playbook 中使用它,请指定:openstack.cloud.security_group

概要

  • 在 OpenStack 云中添加或删除 Neutron 安全组。

要求

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

  • 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* 是一个 dict,它包含一个完整的云配置,就像 clouds.yaml 的一个部分一样。

description

字符串

安全组用途的详细说明。

interface

别名:endpoint_type

字符串

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

选择

  • "admin"

  • "internal"

  • "public" ← (默认)

name

字符串 / 必需

必须给安全组的名称。此模块要求安全组名称是唯一的。

project

字符串

项目的唯一名称或 ID。

region_name

字符串

区域的名称。

sdk_log_level

字符串

OpenStackSDK 的日志级别

选择

  • "INFO" ← (默认)

  • "DEBUG"

sdk_log_path

字符串

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

security_group_rules

列表 / 元素=字典

安全组规则列表。

当未定义 *security_group_rules* 时,Neutron 可能会使用默认规则集创建此安全组。

将创建 *security_group_rules* 中列出但未在此安全组中定义的安全组规则。

当未设置 *security_group_rules* 时,将删除 *security_group_rules* 中未列出的现有安全组规则。

更新安全组时,如果要保留规则,则必须显式列出 *security_group_rules* 中 Neutron 默认值中的规则。未在 *security_group_rules* 中列出的规则将被删除。

description

字符串

安全组规则的说明。

direction

字符串

应用安全组规则的方向。

并非所有提供商都支持 egress

选择

  • "egress"

  • "ingress" ← (默认)

ether_type

字符串

必须为 IPv4 或 IPv6,并且以 CIDR 表示的地址必须与入口或出口规则匹配。并非所有提供商都支持 IPv6。

选择

  • "IPv4" ← (默认)

  • "IPv6"

port_range_max

整数

安全组规则匹配的范围中的最大端口号。

如果协议是 TCP、UDP、DCCP、SCTP 或 UDP-Lite,则此值必须大于或等于 *port_range_min* 属性值。

如果协议是 ICMP,则此值必须是 ICMP 代码。

port_range_min

整数

安全组规则匹配的范围中的最小端口号。

如果协议是 TCP、UDP、DCCP、SCTP 或 UDP-Lite,则此值必须小于或等于 port_range_max 属性值。

如果协议是 ICMP,则此值必须是 ICMP 类型。

protocol

字符串

IP 协议可以用字符串、整数或 null 表示。

有效的字符串或整数值包括 any0ah51dccp33egp8esp50gre47icmp1icmpv658igmp2ipip4ipv6-encap41ipv6-frag44ipv6-icmp58ipv6-nonxt59ipv6-opts60ipv6-route43ospf89pgm113rsvp46sctp132tcp6udp17udplite136vrrp112

此外,任何介于 [0-255] 之间的整数值也是有效的。

字符串 any (或整数 0) 表示所有 IP 协议。

有关支持字符串的最新列表,请参阅 neutron_lib.constants 中的常量。

remote_group

字符串

要链接的安全组的名称或 ID。

remote_ip_prefix 互斥。

remote_ip_prefix

字符串

CIDR 表示法的源 IP 地址。

如果 remote_ip_prefix 中缺少诸如 /32 之类的网络掩码,则此模块将在更新时失败,并显示 OpenStack 错误消息 Security group rule already exists.

remote_group 互斥。

state

字符串

资源应该是存在还是不存在。

选择

  • "present" ← (默认)

  • "absent"

stateful

布尔值

资源应该是有状态还是无状态。

选择

  • false

  • true

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: Create a security group
  openstack.cloud.security_group:
    cloud: mordred
    state: present
    name: foo
    description: security group for foo servers

- name: Create a stateless security group
  openstack.cloud.security_group:
    cloud: mordred
    state: present
    stateful: false
    name: foo
    description: stateless security group for foo servers

- name: Update the existing 'foo' security group description
  openstack.cloud.security_group:
    cloud: mordred
    state: present
    name: foo
    description: updated description for the foo security group

- name: Create a security group for a given project
  openstack.cloud.security_group:
    cloud: mordred
    state: present
    name: foo
    project: myproj

- name: Create (or update) a security group with security group rules
  openstack.cloud.security_group:
    cloud: mordred
    state: present
    name: foo
    security_group_rules:
      - ether_type: IPv6
        direction: egress
      - ether_type: IPv4
        direction: egress

- name: Create (or update) security group without security group rules
  openstack.cloud.security_group:
    cloud: mordred
    state: present
    name: foo
    security_group_rules: []

返回值

通用返回值在此处记录 此处,以下是此模块特有的字段

描述

security_group

字典

描述安全组的字典。

返回:statepresent 时成功返回。

created_at

字符串

安全组的创建时间

返回: 成功

示例: "yyyy-mm-dd hh:mm:ss"

description

字符串

安全组的描述

返回: 成功

示例: "我的 安全组"

id

字符串

安全组的 ID

返回: 成功

示例: "d90e55ba-23bd-4d97-b722-8cb6fb485d69"

name

字符串

安全组的名称。

返回: 成功

示例: "my-sg"

project_id

字符串

安全组所在的 Project ID。

返回: 成功

示例: "25d24fc8-d019-4a34-9fff-0a09fde6a567"

revision_number

整数

资源的修订号。

返回: 成功

security_group_rules

list / elements=string

指定安全组规则列表

返回: 成功

示例: [{"description": null, "direction": "ingress", "ethertype": "IPv4", "id": "d90e55ba-23bd-4d97-b722-8cb6fb485d69", "port_range_max": null, "port_range_min": null, "protocol": null, "remote_group_id": "0431c9c5-1660-42e0-8a00-134bec7f03e2", "remote_ip_prefix": null, "security_group_id": "0431c9c5-1660-42e0-8a00-134bec7f03e2", "tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c"}, {"description": null, "direction": "egress", "ethertype": "IPv4", "id": "aecff4d4-9ce9-489c-86a3-803aedec65f7", "port_range_max": null, "port_range_min": null, "protocol": null, "remote_group_id": null, "remote_ip_prefix": null, "security_group_id": "0431c9c5-1660-42e0-8a00-134bec7f03e2", "tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c"}]

stateful

布尔值

指示安全组是否有状态或无状态。

返回: 成功

tags

list / elements=string

资源上的标签列表。

返回: 成功

tenant_id

字符串

安全组所在的 Tenant ID。 已弃用

返回: 成功

示例: "25d24fc8-d019-4a34-9fff-0a09fde6a567"

updated_at

字符串

安全组的更新时间

返回: 成功

示例: "yyyy-mm-dd hh:mm:ss"

作者

  • OpenStack Ansible SIG