-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nodered): add export external nodes playbook
this playbook queries the `/nodes` API from node-RED and obtain the information external nodes and try downloading it from NPM registry as tarballs in the `deploy_dir/nodered` directory Closes #110 Signed-off-by: Shantanoo 'Shan' Desai <[email protected]>
- Loading branch information
1 parent
67d6695
commit 1c59c0a
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
# | ||
# Komponist - Generate Your Favourite Compose Stack With the Least Effort | ||
# | ||
# Copyright (C) 2023 Shantanoo "Shan" Desai <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
# export_nodes_nodered.yml: Ansible Playbook that exports any external Node-RED nodes | ||
# for offline installation | ||
--- | ||
- name: Export Node-RED Nodes from Node-RED for Offline Installation | ||
hosts: localhost | ||
gather_facts: true | ||
vars_files: | ||
- vars/config.yml | ||
- vars/creds.yml | ||
module_defaults: | ||
ansible.builtin.uri: | ||
method: POST | ||
headers: | ||
Content-Type: application/json | ||
|
||
tasks: | ||
- name: Get Node-RED user with all Privileges | ||
ansible.builtin.set_fact: | ||
nodered_creds: "{{ item }}" | ||
when: "item.permissions is defined and item['permissions'] == '*'" | ||
loop: "{{ credentials.nodered.users }}" | ||
no_log: true | ||
|
||
- 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: Lookup Nodes from Node-RED instance | ||
ansible.builtin.set_fact: | ||
node_set: "{{ lookup('ansible.builtin.url', 'http://localhost/nodered/nodes', headers=headers) }}" | ||
vars: | ||
headers: | ||
Accept: application/json | ||
Authorization: "{{ auth_token.json.token_type }} {{ auth_token.json.access_token }}" | ||
|
||
- name: External Nodes in Node-RED instance | ||
ansible.builtin.get_url: | ||
url: "https://registry.npmjs.org/{{ item.module }}/-/{{ item.module }}-{{ item.version }}.tgz" | ||
dest: "{{ komponist.deploy_dir }}/nodered/" | ||
mode: "0640" | ||
loop: "{{ node_set }}" | ||
when: item.module != 'node-red' | ||
|
||
- 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 |