-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-wgrib2.yml
More file actions
334 lines (288 loc) · 10.9 KB
/
install-wgrib2.yml
File metadata and controls
334 lines (288 loc) · 10.9 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
---
- name: Install wgrib2
hosts: all
become: yes
vars:
# Change version info below as needed
wgrib2_version: "3.5.0"
nceplibs_g2c_version: "2.1.0"
nceplibs_g2_version: "4.0.0"
nceplibs_bacio_version: "2.6.0"
nceplibs_ip_version: "5.2.0"
jasper_version: "4.2.4"
# Below should be left alone past initial configuration
base_source_dir: "/usr/local/src"
jasper_source_dir: "{{ base_source_dir }}/jasper-version-{{ jasper_version }}"
jasper_build_dir: "{{ base_source_dir }}/jasper-version-{{ jasper_version }}-build" # MUST be outside Jasper source directory!
jasper_install_dir: "/usr/local"
nceplibs_g2c_path: "{{ base_source_dir }}/NCEPLIBS-g2c-{{ nceplibs_g2c_version }}"
nceplibs_g2_path: "{{ base_source_dir }}/NCEPLIBS-g2-{{ nceplibs_g2_version }}"
nceplibs_bacio_path: "{{ base_source_dir }}/NCEPLIBS-bacio-{{ nceplibs_bacio_version }}"
nceplibs_ip_path: "{{ base_source_dir }}/NCEPLIBS-ip-{{ nceplibs_ip_version }}"
install_dir: "{{ base_source_dir }}/wgrib2"
bin_dir: "/usr/local/bin"
tasks:
- name: Install dependencies
apt:
name:
- build-essential
- cmake
- gfortran
- libaec-dev
- libblas-dev
- liblapack-dev
- libnetcdf-dev
- libpng-dev
- make
- m4
- zlib1g-dev
state: present
update_cache: yes
# Step 1: Compile and Install Jasper
- name: Download and extract Jasper
get_url:
url: "https://github.com/jasper-software/jasper/archive/refs/tags/version-{{ jasper_version }}.tar.gz"
dest: "/tmp/jasper-{{ jasper_version }}.tar.gz"
- name: Extract Jasper
unarchive:
src: "/tmp/jasper-{{ jasper_version }}.tar.gz"
dest: "{{ base_source_dir }}"
remote_src: yes
- name: Create build directory for Jasper
file:
path: "{{ jasper_build_dir }}"
state: directory
- name: Configure Jasper with CMake
shell: |
cmake -H{{ jasper_source_dir }} -B{{ jasper_build_dir }} -DCMAKE_INSTALL_PREFIX={{ jasper_install_dir }}
args:
executable: /bin/bash
- name: Build Jasper
shell: |
cmake --build {{ jasper_build_dir }}
args:
executable: /bin/bash
# - name: Run Jasper test suite
# shell: |
# cd {{ jasper_build_dir }}
# ctest --output-on-failure
# args:
# executable: /bin/bash
# ignore_errors: yes # Allow the playbook to continue even if tests fail
- name: Install Jasper
shell: |
cmake --build {{ jasper_build_dir }} --target install
args:
executable: /bin/bash
# This avoids a "missing link" issue
- name: Ensure /usr/local/lib is in ld.so.conf
copy:
dest: /etc/ld.so.conf.d/usr-local-lib.conf
content: "/usr/local/lib\n"
mode: "0644"
- name: Reload dynamic linker cache
command: ldconfig
# Step 2: Download and install NCEPLIBS-ip
- name: Ensure NCEPLIBS-ip directory exists
file:
path: "{{ nceplibs_ip_path }}"
state: directory
mode: '0755'
- name: Download NCEPLIBS-ip tarball
get_url:
url: "https://github.com/NOAA-EMC/NCEPLIBS-ip/archive/refs/tags/v{{ nceplibs_ip_version }}.tar.gz"
dest: "/tmp/NCEPLIBS-ip-{{ nceplibs_ip_version }}.tar.gz"
- name: Extract NCEPLIBS-ip tarball
unarchive:
src: "/tmp/NCEPLIBS-ip-{{ nceplibs_ip_version }}.tar.gz"
dest: "{{ base_source_dir }}/"
remote_src: yes
- name: Compile and install NCEPLIBS-ip
shell: |
mkdir -p {{ nceplibs_ip_path }}/build
cd {{ nceplibs_ip_path }}/build
cmake -DCMAKE_INSTALL_PREFIX={{ nceplibs_ip_path }} ..
make
make install
args:
creates: "{{ nceplibs_ip_path }}/lib"
# Step 3: Download and install NCEPLIBS-g2c
- name: Ensure NCEPLIBS-g2c directory exists
file:
path: "{{ nceplibs_g2c_path }}"
state: directory
mode: '0755'
- name: Download NCEPLIBS-g2c tarball
get_url:
url: "https://github.com/NOAA-EMC/NCEPLIBS-g2c/archive/refs/tags/v{{ nceplibs_g2c_version }}.tar.gz"
dest: "/tmp/NCEPLIBS-g2c-{{ nceplibs_g2c_version }}.tar.gz"
- name: Extract NCEPLIBS-g2c tarball
unarchive:
src: "/tmp/NCEPLIBS-g2c-{{ nceplibs_g2c_version }}.tar.gz"
dest: "/usr/local/src"
remote_src: yes
- name: Compile and install NCEPLIBS-g2c
shell: |
mkdir -p {{ nceplibs_g2c_path }}/build
cd {{ nceplibs_g2c_path }}/build
cmake -DCMAKE_INSTALL_PREFIX={{ nceplibs_g2c_path }} -DUSE_Jasper=ON -DJasper_DIR={{ jasper_install_dir }} -DUSE_AEC=ON .. > /tmp/g2c_build.log 2>&1
make > /tmp/g2c_make.log 2>&1
make install > /tmp/g2c_install.log 2>&1
args:
creates: "{{ nceplibs_g2c_path }}/lib"
# Step 4: Install NCEPLIBS-bacio
- name: Download and extract NCEPLIBS-bacio
get_url:
url: "https://github.com/NOAA-EMC/NCEPLIBS-bacio/archive/refs/tags/v{{ nceplibs_bacio_version }}.tar.gz"
dest: "/tmp/NCEPLIBS-bacio-{{ nceplibs_bacio_version }}.tar.gz"
- name: Extract NCEPLIBS-bacio
unarchive:
src: "/tmp/NCEPLIBS-bacio-{{ nceplibs_bacio_version }}.tar.gz"
dest: "/usr/local/src"
remote_src: yes
- name: Build and install NCEPLIBS-bacio
shell: |
mkdir -p /usr/local/src/NCEPLIBS-bacio-{{ nceplibs_bacio_version }}/build
cd /usr/local/src/NCEPLIBS-bacio-{{ nceplibs_bacio_version }}/build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/src/NCEPLIBS-bacio-{{ nceplibs_bacio_version }} ..
make
make install
args:
executable: /bin/bash
# Step 5: Install NCEPLIBS-g2
- name: Download and extract NCEPLIBS-g2
get_url:
url: "https://github.com/NOAA-EMC/NCEPLIBS-g2/archive/refs/tags/v{{ nceplibs_g2_version }}.tar.gz"
dest: "/tmp/NCEPLIBS-g2-{{ nceplibs_g2_version }}.tar.gz"
- name: Extract NCEPLIBS-g2
unarchive:
src: "/tmp/NCEPLIBS-g2-{{ nceplibs_g2_version }}.tar.gz"
dest: "/usr/local/src"
remote_src: yes
- name: Build and install NCEPLIBS-g2
shell: |
mkdir -p {{ nceplibs_g2_path }}/build
cd {{ nceplibs_g2_path }}/build
cmake -DCMAKE_INSTALL_PREFIX={{ nceplibs_g2_path }} -DCMAKE_PREFIX_PATH="{{ nceplibs_g2c_path }};{{ nceplibs_bacio_path }}" -DUSE_AEC=ON -DBUILD_WITH_W3EMC=OFF .. > /tmp/g2_build.log 2>&1
make > /tmp/g2_make.log 2>&1
make install > /tmp/g2_install.log 2>&1
args:
executable: /bin/bash
# Step 6: wgrib2 build and installation
- name: Create installation directory
file:
path: "{{ install_dir }}"
state: directory
mode: '0755'
- name: Download wgrib2 source code
get_url:
url: "https://github.com/NOAA-EMC/wgrib2/archive/refs/tags/v{{ wgrib2_version }}.tar.gz"
dest: "{{ install_dir }}/wgrib2.tgz"
- name: Extract wgrib2 source
unarchive:
src: "{{ install_dir }}/wgrib2.tgz"
dest: "{{ install_dir }}"
remote_src: yes
- name: Create build directory
file:
path: "{{ install_dir }}/wgrib2-{{ wgrib2_version }}/build"
state: directory
mode: '0755'
- name: Run CMake to generate wgrib2 build system
shell: |
export g2c_DIR={{ nceplibs_g2c_path }}/lib/cmake/g2c
export CFLAGS="-I{{ nceplibs_g2c_path }}/include"
export CPPFLAGS="-I{{ nceplibs_g2c_path }}/include"
cd {{ install_dir }}/wgrib2-{{ wgrib2_version }}/build
cmake -DCMAKE_INSTALL_PREFIX={{ nceplibs_ip_path }} \
-DCMAKE_PREFIX_PATH="{{ nceplibs_g2_path }};{{ nceplibs_g2c_path }};{{ nceplibs_ip_path }};{{ jasper_install_dir }}" \
-DUSE_JASPER=ON \
-DUSE_IPOLATES=ON \
-DUSE_AEC=ON \
-DCMAKE_BUILD_TYPE=Release .. > /tmp/wgrib2_build.log 2>&1
args:
executable: /bin/bash
- name: Run make to build wgrib2
community.general.make:
chdir: "{{ install_dir }}/wgrib2-{{ wgrib2_version }}/build"
- name: Run make install to install wgrib2
community.general.make:
chdir: "{{ install_dir }}/wgrib2-{{ wgrib2_version }}/build"
target: install
- name: Ensure wgrib2 compiled successfully
stat:
path: "{{ install_dir }}/wgrib2-{{ wgrib2_version }}/build/wgrib2"
register: wgrib2_bin
- name: Compile gmerge separately
shell: |
cd {{ install_dir }}/wgrib2-{{ wgrib2_version }}/aux_progs
make -f gmerge.make
args:
executable: /bin/bash
- name: Copy wgrib2 binary to /usr/local/bin
copy:
src: "{{ install_dir }}/wgrib2-{{ wgrib2_version }}/build/wgrib2/wgrib2"
dest: "{{ bin_dir }}/wgrib2"
mode: '0755'
remote_src: yes
when: wgrib2_bin.stat.exists
- name: Copy gmerge binary to /usr/local/bin
copy:
src: "{{ install_dir }}/wgrib2-{{ wgrib2_version }}/aux_progs/gmerge"
dest: "{{ bin_dir }}/gmerge"
mode: '0755'
remote_src: yes
- name: Verify installation
command: "wgrib2 --version"
register: wgrib2_test
changed_when: false
ignore_errors: yes
- name: Show wgrib2 test output
debug:
msg: "{{ wgrib2_test.stdout }}"
# Step 7: Clean up
- name: Find NCEPLIBS temporary directories
find:
paths: "/tmp/"
patterns: "NCEPLIBS*"
file_type: directory
register: NCEPLIBS_dirs_to_remove
- name: Debug NCEPLIBS directories to remove
debug:
var: NCEPLIBS_dirs_to_remove.files
- name: Delete NCEPLIBS temporary directories
file:
path: "{{ item.path }}"
state: absent
loop: "{{ NCEPLIBS_dirs_to_remove.files }}"
when: NCEPLIBS_dirs_to_remove.matched > 0
- name: Find Jasper temporary directories
find:
paths: "{{ jasper_source_dir }}"
patterns: "jasper*"
file_type: directory
register: jasper_dirs_to_remove
- name: Debug Jasper directories to remove
debug:
var: jasper_dirs_to_remove.files
- name: Delete Jasper temporary directories
file:
path: "{{ item.path }}"
state: absent
loop: "{{ jasper_dirs_to_remove.files }}"
when: jasper_dirs_to_remove.matched > 0
- name: Find NCEPLIBS temporary build directories in jasper_build_dir
find:
paths: "{{ jasper_build_dir }}"
patterns: "NCEPLIBS*"
file_type: directory
register: nceplibs_dirs_to_remove
- name: Debug NCEPLIBS directories to remove in jasper_build_dir
debug:
var: nceplibs_dirs_to_remove.files
- name: Delete NCEPLIBS temporary build directories in jasper_build_dir
file:
path: "{{ item.path }}"
state: absent
loop: "{{ nceplibs_dirs_to_remove.files }}"
when: nceplibs_dirs_to_remove.matched > 0