community.digitalocean.digital_ocean_firewall 模块 – 管理 DigitalOcean 中的云防火墙

注意

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

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

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

要在 playbook 中使用它,请指定:community.digitalocean.digital_ocean_firewall

community.digitalocean 1.1.0 中的新增功能

概要

  • 此模块可用于在 DigitalOcean 云平台上添加或删除防火墙。

参数

参数

注释

baseurl

字符串

DigitalOcean API 基本 URL。

默认值: "https://api.digitalocean.com/v2"

droplet_ids

列表 / 元素=字符串

要分配给防火墙的 Droplet ID 列表

inbound_rules

列表 / 元素=字典

专门针对进入 DigitalOcean 的入站网络流量的防火墙规则

ports

字符串 / 必需

允许流量通过的端口,单个、范围或全部

protocol

字符串

要接受的网络协议。

选项

  • "udp"

  • "tcp" ←(默认)

  • "icmp"

sources

字典 / 必需

接受入站流量的位置字典

addresses

列表 / 元素=字符串

包含防火墙将允许流量通过的 IPv4 地址、IPv6 地址、IPv4 CIDR 和/或 IPv6 CIDR 的字符串列表

droplet_ids

列表 / 元素=字符串

包含防火墙将允许流量通过的 Droplet ID 的整数列表

load_balancer_uids

列表 / 元素=字符串

包含防火墙将允许流量通过的负载均衡器 ID 的字符串列表

tags

列表 / 元素=字符串

包含与防火墙将允许流量通过的 Droplet 组对应的标签名称的字符串列表

name

字符串 / 必需

要创建或管理的防火墙规则的名称

oauth_token

别名:api_token

字符串

DigitalOcean OAuth 令牌。

还有其他几个环境变量可用于提供此值。

例如,- DO_API_TOKENDO_API_KEYDO_OAUTH_TOKENOAUTH_TOKEN

outbound_rules

列表 / 元素=字典

专门针对从 DigitalOcean 发出的出站网络流量的防火墙规则

destinations

字典 / 必需

允许出站流量的位置字典

addresses

列表 / 元素=字符串

包含防火墙将允许流量通过的 IPv4 地址、IPv6 地址、IPv4 CIDR 和/或 IPv6 CIDR 的字符串列表

droplet_ids

列表 / 元素=字符串

包含防火墙将允许流量通过的 Droplet ID 的整数列表

load_balancer_uids

列表 / 元素=字符串

包含防火墙将允许流量通过的负载均衡器 ID 的字符串列表

tags

列表 / 元素=字符串

包含与防火墙将允许流量通过的 Droplet 组对应的标签名称的字符串列表

ports

字符串 / 必需

允许流量通过的端口,单个、范围或全部

protocol

字符串

要接受的网络协议。

选项

  • "udp"

  • "tcp" ←(默认)

  • "icmp"

state

字符串

断言防火墙规则的状态。设置为 “present” 以创建或更新,设置为 “absent” 以删除。

选项

  • "present" ←(默认)

  • "absent"

tags

列表 / 元素=字符串

要分配给防火墙的标签列表

timeout

整数

用于轮询 DigitalOcean API 的超时时间(以秒为单位)。

默认值: 30

validate_certs

布尔值

如果设置为 no,则不会验证 SSL 证书。

仅应在个人控制的使用自签名证书的站点上设置为 no

选项

  • false

  • true ←(默认)

示例

# Allows tcp connections to port 22 (SSH) from specific sources
# Allows tcp connections to ports 80 and 443 from any source
# Allows outbound access to any destination for protocols tcp, udp and icmp
# The firewall rules will be applied to any droplets with the tag "sample"
- name: Create a Firewall named my-firewall
  digital_ocean_firewall:
    name: my-firewall
    state: present
    inbound_rules:
      - protocol: "tcp"
        ports: "22"
        sources:
          addresses: ["1.2.3.4"]
          droplet_ids: ["my_droplet_id_1", "my_droplet_id_2"]
          load_balancer_uids: ["my_lb_id_1", "my_lb_id_2"]
          tags: ["tag_1", "tag_2"]
      - protocol: "tcp"
        ports: "80"
        sources:
          addresses: ["0.0.0.0/0", "::/0"]
      - protocol: "tcp"
        ports: "443"
        sources:
          addresses: ["0.0.0.0/0", "::/0"]
    outbound_rules:
      - protocol: "tcp"
        ports: "1-65535"
        destinations:
          addresses: ["0.0.0.0/0", "::/0"]
      - protocol: "udp"
        ports: "1-65535"
        destinations:
          addresses: ["0.0.0.0/0", "::/0"]
      - protocol: "icmp"
        ports: "1-65535"
        destinations:
          addresses: ["0.0.0.0/0", "::/0"]
    droplet_ids: []
    tags: ["sample"]

返回值

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

描述

数据

字典

DigitalOcean 防火墙资源

返回:成功

示例: {"created_at": "2020-08-11T18:41:30Z", "droplet_ids": [], "id": "7acd6ee2-257b-434f-8909-709a5816d4f9", "inbound_rules": [{"ports": "443", "protocol": "tcp", "sources": {"addresses": ["1.2.3.4"], "droplet_ids": ["my_droplet_id_1", "my_droplet_id_2"], "load_balancer_uids": ["my_lb_id_1", "my_lb_id_2"], "tags": ["tag_1", "tag_2"]}}, {"ports": "80", "protocol": "tcp", "sources": {"addresses": ["0.0.0.0/0", "::/0"]}}, {"ports": "443", "protocol": "tcp", "sources": {"addresses": ["0.0.0.0/0", "::/0"]}}], "name": "my-firewall", "outbound_rules": [{"destinations": {"addresses": ["0.0.0.0/0", "::/0"]}, "ports": "1-65535", "protocol": "tcp"}, {"destinations": {"addresses": ["0.0.0.0/0", "::/0"]}, "ports": "1-65535", "protocol": "udp"}, {"destinations": {"addresses": ["0.0.0.0/0", "::/0"]}, "ports": "1-65535", "protocol": "icmp"}], "pending_changes": [], "status": "succeeded", "tags": ["sample"]}

作者

  • Anthony Bond (@BondAnthony)

  • Lucas Basquerotto (@lucasbasquerotto)