Closed shantanoo-desai closed 12 months ago
assert
/auth/token
API via HTTP POST/nodes
API via HTTP POST depending on existences of databases---
- name: bootstrap node-RED with komponist related Nodes
hosts: localhost
gather_facts: true
vars_files:
- vars/creds.yml
- vars/config.yml
module_defaults:
ansible.builtin.uri:
method: POST
headers:
Content-Type: application/json
tasks:
- name: Get Node-RED user with all Privileges
set_fact:
nodered_creds: "{{ item }}"
when: "item.permissions is defined and item['permissions'] == '*'"
loop: "{{ credentials.nodered.users }}"
- name: Obtain Authentication Token
ansible.builtin.uri:
url: http://localhost/nodered/auth/token
body:
client_id: node-red-admin
grant_type: password
scope: "{{ nodered_creds.permissions }}"
username: "{{ nodered_creds.username }}"
password: "{{ nodered_creds.password }}"
body_format: json
status_code: 200
register: auth_token
when: nodered_creds is defined
- name: Install InfluxDB Node into Node-RED
ansible.builtin.uri:
url: http://localhost/nodered/nodes
headers:
Authorization: "{{ auth_token.json.token_type }} {{ auth_token.json.access_token }}"
body:
module: "node-red-contrib-influxdb"
body_format: json
status_code: 200
when: "'influxdbv1' in komponist.configuration.keys() or 'influxdbv2' in komponist.configuration.keys()"
- name: Install PostgreSQL Node into Node-RED
ansible.builtin.uri:
url: http://localhost/nodered/nodes
headers:
Authorization: "{{ auth_token.json.token_type }} {{ auth_token.json.access_token }}"
body:
module: "node-red-contrib-postgresql"
body_format: json
status_code: 200
when: "'questdb' in komponist.configuration.keys() or 'timescaledb' in komponist.configuration.keys()"
register: node_results
- name: Revoke Authentication Token
ansible.builtin.uri:
url: http://localhost/nodered/auth/revoke
headers:
Authorization: "{{ auth_token.json.token_type }} {{ auth_token.json.access_token }}"
body:
token: "{{ auth_token.json.access_token }}"
body_format: json
status_code: 200
Description
Depending on the database selected (default: all), provision the Node-RED instance with the following:
node-red-contrib-influxdb
when eitherinfluxdbv1
orinfluxdbv2
or both exists in the configurationnode-red-contrib-postgresql
when eitherquestdb
ortimescaledb
exists in the configuration