-
Notifications
You must be signed in to change notification settings - Fork 1
/
CentOS7x_Install-Node-RED-playbook.yml
168 lines (127 loc) · 5.1 KB
/
CentOS7x_Install-Node-RED-playbook.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
################################################################################
# description: Installs Node-RED on CentOS7x
# usage: ansible-playbook CentOS7x_Install-Node-RED-playbook.yml --extra-vars 'HostOrGroup=YourServerOrGroupNameGoesHere'
# author: Ernest G. Wilson II <ErnestGWilsonII@gmail.com> (https://github.com/ernestgwilsonii)
# license: MIT
################################################################################
# Ansible Playbook options
# REF: http://docs.ansible.com/ansible/playbooks.html
#####################################################
- name: Install Node-RED on CentOS7x
hosts: "{{ HostOrGroup|default ('FATAL ERROR --> HostOrGroup NOT SET! You must specify either a Host or a Group name!') }}"
serial: "100%"
gather_facts: False
tasks:
# Install yum packages (listed in alphabetical order)
# REF: http://docs.ansible.com/ansible/yum_module.html
######################################################
- name: Install lsof
yum:
name=lsof
state=latest
# group - Add or remove groups
# REF: http://docs.ansible.com/ansible/group_module.html
########################################################
- name: Add group nodered to the OS (if not already present) for Node-RED
user:
name: nodered
state: present
# Create and manage user accounts
# REF: http://docs.ansible.com/ansible/user_module.html
#######################################################
- name: Add user nodered to the OS (if not already present) so Node-RED does not run as root
user:
name: nodered
comment: nodered
group: nodered
state: present
# unarchive - Unpacks an archive after (optionally) copying it from the local machine
# REF: http://docs.ansible.com/ansible/unarchive_module.html
############################################################
# https://github.com/node-red/node-red/releases
- name: Download and extract the latest release of Node-RED
unarchive:
src: https://github.com/node-red/node-red/archive/0.16.2.tar.gz
dest: /opt
copy: no
# file - Sets attributes of files and directories
# http://docs.ansible.com/ansible/file_module.html
##################################################
- name: Create symbolic link
file:
src: /opt/node-red-0.16.2
dest: /opt/node-red
owner: nodered
group: nodered
state: link
# Use npm to install and manage Node.js packages
# REF: http://docs.ansible.com/ansible/npm_module.html
######################################################
- name: Run npm install in /opt/node-red
npm:
path: /opt/node-red
state: latest
global: no
# raw - Executes a low-down and dirty SSH command
# REF: http://docs.ansible.com/ansible/raw_module.html
######################################################
- name: cd /opt/node-red && npm install bcrypt --save
shell: cd /opt/node-red && npm install bcrypt --save
- name: cd /opt/node-red && npm run build
shell: cd /opt/node-red && npm run build
# file - Sets attributes of files and directories
# http://docs.ansible.com/ansible/file_module.html
##################################################
- name: Set directory permisions on /opt/node-red
file:
path: /opt/node-red-0.16.2
recurse: yes
follow: yes
owner: nodered
group: nodered
# Restart firewalld to make sure it is running OK before changing any rules
# REF: http://docs.ansible.com/ansible/service_module.html
##########################################################
- name: Ensure the firewalld service is enabled and re-started before changing any rules
service:
name: firewalld
enabled: yes
state: restarted
# Update the firewalld configuration
# REF: http://docs.ansible.com/ansible/firewalld_module.html
############################################################
- name: Update firewall to allow port TCP 1880 for incoming Node-RED connections
firewalld:
port: 1880/tcp
permanent: true
immediate: yes
state: enabled
zone: public
# Use the template module to populate files with data
# REF: http://docs.ansible.com/ansible/template_module.html
###########################################################
# /etc/systemd/system/node-red.service
- name: Fill in the variables and copy templates/Node-RED/node-red.service.j2 to remote /etc/systemd/system/node-red.service
template:
src: templates/Node-RED/node-red.service.j2
dest: /etc/systemd/system/node-red.service
owner: root
group: wheel
mode: 0644
# Start Node-RED
# REF: http://docs.ansible.com/ansible/service_module.html
##########################################################
- name: Ensure the Node-RED service (node-red) is enabled and started
service:
name=node-red.service
enabled=yes
state=restarted
# Remote SSH command line trouble-shooting commands:
# systemctl status node-red
# cat /etc/systemd/system/node-red.service
# ls -alF /opt/node-red
# ls -alF /opt/node-red/
# cat /var/log/messages
# ss -ntlup | grep 1880
# lsof -P | grep IPv4 | sort -t: -k2,2n | grep 1880