Skip to content

Commit 53472a1

Browse files
committed
(tasks) Fix install_linux download and subcommand execution
* Ensure facts/tasks/bash.sh is included in task metadata so we can call it * Fix repo defaults to be https * Fix package_url assignment not to duplicate protocol from repository * Capture and log command output and status before exiting for a failed subshell command
1 parent b14fd83 commit 53472a1

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.modules
22
.plan_cache.json
3+
.rerun.json
4+
.resource_types
35
.task_cache.json
46
Puppetfile

tasks/install.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
"apt_source": {
1414
"description": "The apt source repository to retrieve deb packages from.",
1515
"type": "Optional[String]",
16-
"default": "http://apt.overlookinfratech.com"
16+
"default": "https://apt.overlookinfratech.com"
1717
},
1818
"yum_source": {
1919
"description": "The yum source repository to retrieve rpm packages from.",
2020
"type": "Optional[String]",
21-
"default": "http://yum.overlookinfratech.com"
21+
"default": "https://yum.overlookinfratech.com"
2222
}
2323
},
2424
"implementations": [
25-
{"name": "install_linux.sh", "requirements": ["shell"]}
25+
{
26+
"name": "install_linux.sh",
27+
"requirements": ["shell"],
28+
"files": ["facts/tasks/bash.sh"]
29+
}
2630
]
2731
}

tasks/install_linux.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ set_platform() {
6161
full_version=$(bash "${facts}" release)
6262
assigned 'full_version'
6363
else
64-
fail "Unable to find the puppetlabs-facts bash task to determine platform."
64+
fail "Unable to find the puppetlabs-facts bash task to determine platform at '${facts}'."
6565
fi
6666
}
6767

@@ -140,21 +140,37 @@ set_collection_url() {
140140
else
141141
package_name="${collection}-release-${family}${full_version}.${package_file_suffix}"
142142
fi
143-
package_url="https://${repository}/${package_name}"
143+
package_url="${repository}/${package_name}"
144144

145145
assigned 'package_name'
146146
assigned 'package_url'
147147
}
148148

149+
exec_and_capture() {
150+
local _cmd="$*"
151+
152+
info "Executing: ${_cmd}"
153+
local _result
154+
155+
set +e
156+
result=$(${_cmd} 2>&1)
157+
local _status=$?
158+
set -e
159+
160+
echo "${result}"
161+
info "Status: ${_status}"
162+
return $_status
163+
}
164+
149165
# Download the given url to the given local file path.
150166
download() {
151167
local _url="$1"
152168
local _file="$2"
153169

154170
if exists 'wget'; then
155-
wget -O "${_file}" "${_url}"
171+
exec_and_capture wget -O "${_file}" "${_url}"
156172
elif exists 'curl'; then
157-
curl -sSL -o "${_file}" "${_url}"
173+
exec_and_capture curl -sSL -o "${_file}" "${_url}"
158174
else
159175
fail "Unable to download ${_url}. Neither wget nor curl are installed."
160176
fi
@@ -180,13 +196,14 @@ install_release_package() {
180196
local _package_type="$1"
181197
local _package_file="$2"
182198

199+
info "Installing release package: ${_package_file}"
183200
case $_package_type in
184201
rpm)
185-
rpm -Uvh "$_package_file"
202+
exec_and_capture rpm -Uvh "$_package_file"
186203
;;
187204
deb)
188-
dpkg -i "$_package_file"
189-
apt update
205+
exec_and_capture dpkg -i "$_package_file"
206+
exec_and_capture apt update
190207
;;
191208
*)
192209
fail "Unhandled package type: '${package_type}'"
@@ -197,14 +214,15 @@ install_release_package() {
197214
install_package() {
198215
local _package="$1"
199216

217+
info "Installing ${_package}"
200218
if exists 'dnf'; then
201-
dnf install -y "$_package"
219+
exec_and_capture dnf install -y "$_package"
202220
elif exists 'yum'; then
203-
yum install -y "$_package"
221+
exec_and_capture yum install -y "$_package"
204222
elif exists 'zypper'; then
205-
zypper install -y "$_package"
223+
exec_and_capture zypper install -y "$_package"
206224
elif exists 'apt'; then
207-
apt install -y "$_package"
225+
exec_and_capture apt install -y "$_package"
208226
else
209227
fail "Unable to install ${_package}. Neither dnf, yum, zypper, nor apt are installed."
210228
fi

0 commit comments

Comments
 (0)