-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlang_javascript.playbook.yml
More file actions
179 lines (160 loc) · 7.03 KB
/
Copy pathlang_javascript.playbook.yml
File metadata and controls
179 lines (160 loc) · 7.03 KB
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
169
170
171
172
173
174
175
176
177
178
179
# This file is part of Werkstatt.
#
# Werkstatt is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Werkstatt 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Werkstatt. If not, see <https://www.gnu.org/licenses/>.
##
# Ansible playbook that installs the Node.js server-side run-time for
# JavaScript and other useful programmes for working with it.
#
# @see {@link https://nodejs.org}
# @author Geoffrey Bernardo van Wyk <geoffrey@vanwyk.biz>
# @copyright 2024 Geoffrey Bernardo van Wyk {@link https://geoffreyvanwyk.dev}
# @license {@link http://www.gnu.org/copyleft/gpl.html} GNU GPL v3 or later
##
---
- name: JavaScript Programming Language
hosts: all
tasks:
- name: Set JavaScript facts for Werkstatt
ansible.builtin.set_fact:
werkstatt_nodenv_version: 1.4.1
werkstatt_nodebuild_version: 4.9.143
werkstatt_node_version: 21.7.3
werkstatt_nodenv_root: "{{ ansible_env.HOME }}/.nodenv"
werkstatt_nodenv: "{{ ansible_env.HOME }}/.nodenv/bin/nodenv"
werkstatt_node: "{{ ansible_env.HOME }}/.nodenv/shims/node"
werkstatt_npm: "{{ ansible_env.HOME }}/.nodenv/shims/npm"
werkstatt_npx: "{{ ansible_env.HOME }}/.nodenv/shims/npx"
werkstatt_yarn: "{{ ansible_env.HOME }}/.nodenv/shims/yarn"
##
# nodenv provides simple Node.js version management.
#
# Installs nodenv, then set the global Node version to the latest stable
# version.
#
# @see {@link https://github.com/nodenv/nodenv}
##
- name: NODENV
hosts: all
tasks:
- name: Installation of nodenv & node-build
block:
- name: Clone nodenv source code repository
ansible.builtin.git:
repo: https://github.com/nodenv/nodenv
version: "v{{ werkstatt_nodenv_version }}"
dest: "{{ werkstatt_nodenv_root }}"
- name: Create directory for nodenv plugins
ansible.builtin.file:
path: "{{ werkstatt_nodenv_root }}/plugins"
state: directory
mode: u=rwX,go=rX
- name: Clone node-build source code repository
ansible.builtin.git:
repo: https://github.com/nodenv/node-build
version: v{{ werkstatt_nodebuild_version }}
dest: "{{ werkstatt_nodenv_root }}/plugins/node-build"
- name: Integrate nodenv with bash
block:
- name: Add bash environment variables for nodenv
vars:
bash_envs_to_add:
NODENV_ROOT: "{{ werkstatt_nodenv_root }}"
ansible.builtin.include_tasks: tasks/bash_add_env.yml
- name: Add bash executable path for nodenv
vars:
bash_paths_to_add:
- "{{ werkstatt_nodenv_root }}/bin"
ansible.builtin.include_tasks: tasks/bash_add_paths.yml
- name: Add bash plugin for nodenv
vars:
bash_plugins_to_add:
- 'eval "$(nodenv init -)"'
ansible.builtin.include_tasks: tasks/bash_add_plugins.yml
- name: Installation of latest Node
block:
- name: Is required Node version already installed?
ansible.builtin.stat:
path: "{{ werkstatt_nodenv_root }}/versions/{{ werkstatt_node_version }}"
register: werkstatt_stat_node_version
- name: Install Node
when: not werkstatt_stat_node_version.stat.exists
ansible.builtin.shell:
executable: /usr/bin/bash
cmd: "{{ werkstatt_nodenv }} install {{ werkstatt_node_version }}"
changed_when: not werkstatt_stat_node_version.stat.exists
- name: Has a global Node version been set?
ansible.builtin.stat:
path: "{{ werkstatt_nodenv_root }}/version"
register: werkstatt_stat_node_global_version
- name: Obtain current global Node version
when: werkstatt_stat_node_global_version.stat.exists
ansible.builtin.shell:
executable: /usr/bin/bash
chdir: "{{ werkstatt_nodenv_root }}"
cmd: \cat version
changed_when: false
register: werkstatt_current_node_global_version
- name: Is current global Node the desired version?
ansible.builtin.set_fact:
werkstatt_is_global_node_version_correct: "{{
werkstatt_stat_node_global_version.stat.exists
and
werkstatt_current_node_global_version.stdout == werkstatt_node_version }}"
- name: Set global Node version
when: not werkstatt_is_global_node_version_correct
ansible.builtin.shell:
executable: /usr/bin/bash
cmd: "{{ werkstatt_nodenv }} global {{ werkstatt_node_version }}"
changed_when: not werkstatt_is_global_node_version_correct
- name: Install global Node packages
block:
- name: List out all global packages installed with npm
ansible.builtin.command:
cmd: "{{ werkstatt_npm }} ls --global"
changed_when: false
register: werkstatt_list_of_global_npm_packages
##
# Yarn is a package manager that doubles down as project manager.
# Whether you work on simple projects or industry monorepos, whether
# you're an open source developer or an enterprise user, Yarn has
# your back.
#
# @see {@link https://www.yarnpkg.com}
##
- name: Install yarn
when: not 'yarn' in werkstatt_list_of_global_npm_packages.stdout
ansible.builtin.command:
cmd: "{{ werkstatt_npm }} install --global yarn"
changed_when: not 'yarn' in werkstatt_list_of_global_npm_packages.stdout
##
# Grunt is a JavaScript task runner.
#
# @see {@link https://www.gruntjs.com}
##
- name: Install grunt
when: not 'grunt-cli' in werkstatt_list_of_global_npm_packages.stdout
ansible.builtin.command:
cmd: "{{ werkstatt_npm }} install --global grunt-cli"
changed_when: not 'grunt-cli' in werkstatt_list_of_global_npm_packages.stdout
##
# Gulp is a toolkit to automate & enhance your workflow. Leverage gulp
# and the flexibility of JavaScript to automate slow, repetitive
# workflows and compose them into efficient build pipelines.
#
# @see {@link https://www.gulpjs.com}
##
- name: Install gulp
when: not 'gulp-cli' in werkstatt_list_of_global_npm_packages.stdout
ansible.builtin.command:
cmd: "{{ werkstatt_npm }} install --global gulp-cli"
changed_when: not 'gulp-cli' in werkstatt_list_of_global_npm_packages.stdout