community.general.consul_policy 模块 – 操作 Consul 策略
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您正在使用 ansible 包,您可能已经安装了这个集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定:community.general.consul_policy。
community.general 7.2.0 中的新增功能
概要
- 允许通过代理在 Consul 集群中添加、修改和删除策略。有关使用和配置 ACL 的更多详细信息,请参阅 https://www.consul.io/docs/guides/acl.html。 
参数
| 参数 | 注释 | 
|---|---|
| 用于 https 连接的 CA 包 | |
| 策略的描述。 | |
| Consul 代理的主机,默认为  默认值:  | |
| 应该与策略关联的名称,这对 Consul 是不透明的。 | |
| Consul 代理正在运行的端口。 默认值:  | |
| 应该与当前策略关联的规则文档。 | |
| Consul 代理正在运行的协议方案。默认为  默认值:  | |
| 策略应该是存在还是不存在。 选择 
 | |
| 用于授权的令牌。 | |
| 策略的有效数据中心。如果列表为空,则为全部。 | |
| 是否验证 Consul 代理的 TLS 证书。 选择 
 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 操作组: community.general.consul 在 community.general 8.3.0 中添加 | 在  | |
| 支持:完全 在 community.general 8.3.0 中添加 | 可以在  | |
| 支持:部分 在 community.general 8.3.0 中添加 在检查模式下,diff 会遗漏操作属性。 | 当处于 diff 模式时,将返回有关已更改的内容(或可能需要在  | 
示例
- name: Create a policy with rules
  community.general.consul_policy:
    host: consul1.example.com
    token: some_management_acl
    name: foo-access
    rules: |
        key "foo" {
            policy = "read"
        }
        key "private/foo" {
            policy = "deny"
        }
- name: Update the rules associated to a policy
  community.general.consul_policy:
    host: consul1.example.com
    token: some_management_acl
    name: foo-access
    rules: |
        key "foo" {
            policy = "read"
        }
        key "private/foo" {
            policy = "deny"
        }
        event "bbq" {
            policy = "write"
        }
- name: Remove a policy
  community.general.consul_policy:
    host: consul1.example.com
    token: some_management_acl
    name: foo-access
    state: absent
返回值
常见的返回值记录在 此处,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| 执行的操作。 已返回: changed 示例:  | |
| Consul HTTP API 返回的策略。 已返回: always 示例:  | 
