community.general.pubnub_blocks (8.5.0) — module

PubNub blocks management module

Authors: PubNub <support@pubnub.com> (@pubnub), Sergey Mamontov <sergey@pubnub.com> (@parfeon)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

This module allows Ansible to interface with the PubNub BLOCKS infrastructure by providing the following operations: create / remove, start / stop and rename for blocks and create / modify / remove for event handlers.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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 }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
name:
    description:
    - Name of managed block which will be later visible on admin.pubnub.com.
    required: true
    type: str

cache:
    default: {}
    description: 'In case if single play use blocks management module few times it is
      preferred to enabled ''caching'' by making previous module to share gathered artifacts
      and pass them to this parameter.

      '
    required: false
    type: dict

email:
    default: ''
    description:
    - Email from account for which new session should be started.
    - Not required if O(cache) contains result of previous module call (in same play).
    required: false
    type: str

state:
    choices:
    - started
    - stopped
    - present
    - absent
    default: present
    description:
    - Intended block state after event handlers creation / update process will be completed.
    required: false
    type: str

keyset:
    description:
    - Name of application's keys set which is bound to managed blocks.
    required: true
    type: str

account:
    default: ''
    description:
    - Name of PubNub account for from which O(application) will be used to manage blocks.
    - User's account will be used if value not set or empty.
    type: str

changes:
    default: {}
    description:
    - List of fields which should be changed by block itself (doesn't affect any event
      handlers).
    - 'Possible options for change is: O(name).'
    required: false
    type: dict

password:
    default: ''
    description:
    - Password which match to account to which specified O(email) belong.
    - Not required if O(cache) contains result of previous module call (in same play).
    required: false
    type: str

application:
    description:
    - Name of target PubNub application for which blocks configuration on specific O(keyset)
      will be done.
    required: true
    type: str

description:
    description:
    - Short block description which will be later visible on admin.pubnub.com. Used only
      if block doesn't exists and won't change description for existing block.
    required: false
    type: str

event_handlers:
    default: []
    description:
    - List of event handlers which should be updated for specified block O(name).
    - 'Each entry for new event handler should contain: C(name), C(src), C(channels),
      C(event). C(name) used as event handler name which can be used later to make changes
      to it.'
    - C(src) is full path to file with event handler code.
    - C(channels) is name of channel from which event handler is waiting for events.
    - 'C(event) is type of event which is able to trigger event handler: C(js-before-publish),
      C(js-after-publish), C(js-after-presence).'
    - Each entry for existing handlers should contain C(name) (so target handler can be
      identified). Rest parameters (C(src), C(channels) and C(event)) can be added if
      changes required for them.
    - It is possible to rename event handler by adding C(changes) key to event handler
      payload and pass dictionary, which will contain single key C(name), where new name
      should be passed.
    - To remove particular event handler it is possible to set C(state) for it to C(absent)
      and it will be removed.
    elements: dict
    required: false
    type: list

validate_certs:
    default: true
    description:
    - This key allow to try skip certificates check when performing REST API calls. Sometimes
      host may have issues with certificates on it and this will cause problems to call
      PubNub REST API.
    - If check should be ignored V(false) should be passed to this parameter.
    required: false
    type: bool

Outputs

module_cache:
  description:
  - Cached account information. In case if with single play module used few times
    it is better to pass cached data to next module calls to speed up process.
  returned: always
  type: dict