-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport_nodes_nodered.yml
104 lines (97 loc) · 3.75 KB
/
export_nodes_nodered.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 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
tags: [always]
- 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
tags: [always]
- 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 }}"
tags: [always]
- name: Set external_nodes Fact
ansible.builtin.set_fact:
external_nodes: "{{ external_nodes + [node_module] }}"
vars:
external_nodes: []
node_module:
module: "{{ item.module }}"
version: "{{ item.version }}"
when: item.module != 'node-red' and node_module not in external_nodes
loop: "{{ node_set }}"
tags: [always]
- name: Generate nodes.json File for External Node Modules
ansible.builtin.copy:
dest: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/nodered/nodes.json"
content: "{{ external_nodes | to_nice_json }}"
mode: "0640"
tags: [always]
- 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 | default(ansible_user_dir + '/.komponist') }}/nodered/"
mode: "0640"
loop: "{{ external_nodes }}"
tags: [never, offline]
- 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
tags: [always]