community.general.pubnub_blocks 模块 – PubNub 块管理模块

注意

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

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

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

要在剧本中使用它,请指定:community.general.pubnub_blocks

概要

  • 此模块允许 Ansible 通过提供以下操作来与 PubNub BLOCKS 基础结构交互:创建/删除、启动/停止和重命名块,以及为事件处理程序创建/修改/删除。

要求

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

  • pubnub_blocks_client >= 1.0

参数

参数

注释

account

字符串

PubNub 帐户的名称,从中将使用 application 来管理块。

如果值未设置或为空,则将使用用户的帐户。

默认值: ""

application

字符串 / 必需

目标 PubNub 应用程序的名称,将在其上针对特定 keyset 执行块配置。

cache

字典

如果单个剧本多次使用块管理模块,则最好通过使之前的模块共享收集到的工件并将它们传递给此参数来启用“缓存”。

默认值: {}

changes

字典

块本身应更改的字段列表(不影响任何事件处理程序)。

更改的可能选项是:name

默认值: {}

description

字符串

简短的块描述,稍后将在 admin.pubnub.com 上显示。仅当块不存在时使用,并且不会更改现有块的描述。

email

字符串

应为其启动新会话的帐户的电子邮件。

如果 cache 包含先前模块调用(在同一剧本中)的结果,则不需要。

默认值: ""

event_handlers

列表 / 元素=字典

应为指定的块 name 更新的事件处理程序列表。

每个新事件处理程序的条目应包含:namesrcchannelseventname 用作事件处理程序名称,稍后可用于对其进行更改。

src 是包含事件处理程序代码的文件的完整路径。

channels 是事件处理程序正在等待事件的通道的名称。

event 是能够触发事件处理程序的事件类型:js-before-publishjs-after-publishjs-after-presence

每个现有处理程序的条目应包含 name(以便可以识别目标处理程序)。如果需要更改,可以添加其余参数(srcchannelsevent)。

可以通过将 changes 键添加到事件处理程序有效负载并传递字典来重命名事件处理程序,该字典将包含单个键 name,其中应传递新名称。

要删除特定事件处理程序,可以将其 state 设置为 absent,它将被删除。

默认值: []

keyset

字符串 / 必需

绑定到已管理块的应用程序密钥集的名称。

name

字符串 / 必需

已管理块的名称,稍后将在 admin.pubnub.com 上显示。

password

字符串

与指定 email 对应的帐户密码。

如果 cache 包含先前模块调用(在同一剧本中)的结果,则不需要。

默认值: ""

state

字符串

事件处理程序创建/更新过程完成后预期的块状态。

选择

  • "started"

  • "stopped"

  • "present" ← (默认)

  • "absent"

validate_certs

布尔值

此密钥允许在执行 REST API 调用时尝试跳过证书检查。有时主机可能存在证书问题,这将导致调用 PubNub REST API 出现问题。

如果应忽略检查,则应将false传递给此参数。

选择

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持:完全支持

可以在check_mode下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:不支持

在差异模式下,将返回有关已更改内容(或可能需要在check_mode中更改的内容)的详细信息。

示例

# Event handler create example.
- name: Create single event handler
  community.general.pubnub_blocks:
    email: '{{ email }}'
    password: '{{ password }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    event_handlers:
      -
        src: '{{ path_to_handler_source }}'
        name: '{{ handler_name }}'
        event: 'js-before-publish'
        channels: '{{ handler_channel }}'

# Change event handler trigger event type.
- name: Change event handler 'event'
  community.general.pubnub_blocks:
    email: '{{ email }}'
    password: '{{ password }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    event_handlers:
      -
        name: '{{ handler_name }}'
        event: 'js-after-publish'

# Stop block and event handlers.
- name: Stopping block
  community.general.pubnub_blocks:
    email: '{{ email }}'
    password: '{{ password }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    state: stop

# Multiple module calls with cached result passing
- name: Create '{{ block_name }}' block
  register: module_cache
  community.general.pubnub_blocks:
    email: '{{ email }}'
    password: '{{ password }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    state: present
- name: Add '{{ event_handler_1_name }}' handler to '{{ block_name }}'
  register: module_cache
  community.general.pubnub_blocks:
    cache: '{{ module_cache }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    state: present
    event_handlers:
      -
        src: '{{ path_to_handler_1_source }}'
        name: '{{ event_handler_1_name }}'
        channels: '{{ event_handler_1_channel }}'
        event: 'js-before-publish'
- name: Add '{{ event_handler_2_name }}' handler to '{{ block_name }}'
  register: module_cache
  community.general.pubnub_blocks:
    cache: '{{ module_cache }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    state: present
    event_handlers:
      -
        src: '{{ path_to_handler_2_source }}'
        name: '{{ event_handler_2_name }}'
        channels: '{{ event_handler_2_channel }}'
        event: 'js-before-publish'
- name: Start '{{ block_name }}' block
  register: module_cache
  community.general.pubnub_blocks:
    cache: '{{ module_cache }}'
    application: '{{ app_name }}'
    keyset: '{{ keyset_name }}'
    name: '{{ block_name }}'
    state: started

返回值

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

描述

module_cache

字典

缓存的帐户信息。如果单个 Play 模块使用多次,最好将缓存的数据传递给后续模块调用以加快处理速度。

返回值:始终返回

作者

  • PubNub (@pubnub)

  • Sergey Mamontov (@parfeon)