Skip to content

Commit e4bbb13

Browse files
committed
Exit install early if nothing to do
This is intended to match the behavior of puppetlabs-puppet_agent's install script, which has similar logic. The logic also appears necessary for OpenBolt's tests to pass. In OpenBolt, a remote node with an agent installed on it, but which has not had apply_prep executed will be initially identified as "agentless". That causes this install script to be invoked via the puppet_library hook. In at least one OpenBolt test this does not _run_as root, so it relies on this bail-out logic to avoid failing when attempting to install the package. After that initial apply_prep run, the puppet-agent feature is added to the Target configuration, which bypasses invoking this installation script in subsequent runs. Initially I thought this might be a bug, but nothing else seems to add the puppet-agent feature to a target configuration so my best guess is that this is how OpenBolt is intended to "detect" the existence of an agent on a remote node.
1 parent d517aca commit e4bbb13

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tasks/install_linux.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ stop_service=${PT_stop_service:-'false'}
1414
# shellcheck source=files/common.sh
1515
source "${PT__installdir}/openvox_bootstrap/files/common.sh"
1616

17+
# This function will cause the script to exit if one of the conditions is met
18+
#
19+
# If the requested $version is
20+
# 1. latest and there is already an agent installed
21+
# 2. not latest, but $version matches the agent's version number
22+
skip_if_installed() {
23+
if [ -f /opt/puppetlabs/puppet/VERSION ]; then
24+
installed_version=$(cat /opt/puppetlabs/puppet/VERSION)
25+
elif command -v puppet >/dev/null 2>&1; then
26+
installed_version=$(puppet --version)
27+
else
28+
installed_version=none
29+
fi
30+
31+
if [ "$installed_version" != 'none' ]; then
32+
if [ "$version" = 'latest' ]; then
33+
info 'Specific agent version not requested and the agent was detected. Skipping install.'
34+
exit 0
35+
elif [ "$version" = "$installed_version" ]; then
36+
# installed agent version matched specific version requested
37+
info "Requested agent version $version. Found agent version $installed_version. Skipping install."
38+
exit 0
39+
fi
40+
fi
41+
}
42+
1743
# Based on platform family set:
1844
# repository - the package repository to download from
1945
set_repository() {
@@ -65,6 +91,8 @@ install_release_package() {
6591
refresh_package_cache
6692
}
6793

94+
# quit early if nothing to do
95+
skip_if_installed
6896
# Get platform information
6997
set_platform_globals
7098
# Set collection release package url based on platform

0 commit comments

Comments
 (0)