community.rabbitmq.rabbitmq_user 模块 – 管理 RabbitMQ 用户

注意

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

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

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

要在 playbook 中使用它,请指定:community.rabbitmq.rabbitmq_user

概要

  • 向 RabbitMQ 添加或删除用户并分配权限

参数

参数

注释

configure_priv

字符串

用于限制指定 vhost 上的资源配置操作的正则表达式。

默认情况下,所有操作都受到限制。

当使用 permissions 选项时,此选项将被忽略。

默认值: "^$"

force

布尔值

删除并重新创建用户。

选择

  • false ← (默认)

  • true

login_host

字符串

在 community.rabbitmq 1.3.0 中添加

API 的主机名。

login_password

字符串

在 community.rabbitmq 1.3.0 中添加

管理 API 的登录密码。

login_port

字符串

在 community.rabbitmq 1.3.0 中添加

从 API 访问的登录端口。

默认值: "15672"

login_protocol

字符串

在 community.rabbitmq 1.3.0 中添加

指定将使用哪个 TCP/IP 协议。

选择

  • "http" ← (默认)

  • "https"

login_user

字符串

在 community.rabbitmq 1.3.0 中添加

管理 API 的管理员用户名。

node

字符串

我们要配置的 rabbit 的 erlang 节点名称

默认值: "rabbit"

password

字符串

要添加的用户的密码。

要更改现有用户的密码,您还必须指定 update_password=always

permissions

列表 / 元素=字典

一个字典列表,每个字典包含 vhost、configure_priv、write_priv 和 read_priv,并表示该 vhost 的权限规则。

当您关心用户的所有权限时,此选项应该是首选。

如果您只关心某些 vhost 的权限,则应该使用 vhost、configure_priv、write_priv 和 read_priv 选项。

默认值: []

read_priv

字符串

用于限制指定 vhost 上的资源配置操作的正则表达式。

默认情况下,所有操作都受到限制。

当使用 permissions 选项时,此选项将被忽略。

默认值: "^$"

state

字符串

指定是要添加还是删除用户

选择

  • "present" ← (默认)

  • "absent"

tags

字符串

用户标签指定为逗号分隔。

建议使用的标签是 management、policymaker、monitoring 和 administrator。

topic_permissions

列表 / 元素=字典

在 community.rabbitmq 1.2.0 中添加

一个字典列表,每个字典包含 vhost、exchange、read_priv 和 write_priv,并表示该 vhost 的主题权限规则。

默认情况下,vhost 为 /,exchange 为 amq.topic

自 RabbitMQ 3.7.0 起支持。如果 RabbitMQ 版本较旧且设置了 topic_permissions,则模块将失败。

默认值: []

update_password

字符串

on_create 将仅为新创建的用户设置密码。always 将在密码不同时更新密码。

选择

  • "on_create" ← (默认)

  • "always"

user

别名:username, name

字符串 / 必需

要添加的用户的名称

vhost

字符串

应用访问权限的 vhost。

当使用 permissions 选项时,此选项将被忽略。

默认值: "/"

write_priv

字符串

用于限制指定 vhost 上的资源配置操作的正则表达式。

默认情况下,所有操作都受到限制。

当使用 permissions 选项时,此选项将被忽略。

默认值: "^$"

示例

- name: |-
    Add user to server and assign full access control on / vhost.
    The user might have permission rules for other vhost but you don't care.
  community.rabbitmq.rabbitmq_user:
    user: joe
    password: changeme
    vhost: /
    configure_priv: .*
    read_priv: .*
    write_priv: .*
    state: present

- name: |-
    Add user to server and assign full access control on / vhost.
    The user doesn't have permission rules for other vhosts
  community.rabbitmq.rabbitmq_user:
    user: joe
    password: changeme
    permissions:
      - vhost: /
        configure_priv: .*
        read_priv: .*
        write_priv: .*
    state: present

- name: |-
    Add user to server and assign some topic permissions on / vhost.
    The user doesn't have topic permission rules for other vhosts
  community.rabbitmq.rabbitmq_user:
    user: joe
    password: changeme
    topic_permissions:
      - vhost: /
        exchange: amq.topic
        read_priv: .*
        write_priv: 'prod\\.logging\\..*'
    state: present

- name: |-
    Add or Update a user using the API
  community.rabbitmq.rabbitmq_user:
    user: joe
    password: changeme
    tags: monitoring
    login_protocol: https
    login_host: localhost
    login_port: 15672
    login_user: admin
    login_password: changeadmin
    permissions:
          - vhost: /
            configure_priv: .*
            read_priv: .*
            write_priv: .*
    topic_permissions:
      - vhost: /
        exchange: amq.topic
        read_priv: .*
        write_priv: 'prod\\.logging\\..*'
    state: present


- name: |-
    Remove a user using the API
  community.rabbitmq.rabbitmq_user:
    user: joe
    password: changeme
    tags: monitoring
    login_protocol: https
    login_host: localhost
    login_port: 15672
    login_user: admin
    login_password: changeadmin
    state: absent

作者

  • Chris Hoffman (@chrishoffman)