@@ -185,15 +185,16 @@ jobs:
185185 shell : bash
186186 run : |
187187 set -Eeuo pipefail
188+ set -o pipefail
188189
189- # Determine version (from metadata.json), fall back to 0.0.0
190+ # --- Determine module version (fallback to 0.0.0)
190191 VER="$(ruby -rjson -e 'puts JSON.parse(File.read("metadata.json"))["version"]' 2>/dev/null || true)"
191- [[ -n "$VER" ]] || VER="0.0.0"
192+ [[ -n "${ VER:-} " ]] || VER="0.0.0"
192193
194+ # --- Build module tarball
193195 mkdir -p pkg stage && rm -rf stage/puppetlabs-ntp
194196 mkdir -p stage/puppetlabs-ntp
195197
196- # Copy module content, skip CI/build noise
197198 shopt -s dotglob
198199 for item in *; do
199200 case "$item" in
@@ -207,46 +208,83 @@ jobs:
207208 tar -C stage -czf "${TAR}" puppetlabs-ntp
208209 echo "Built module archive: ${TAR}"
209210
210- # All targets (master + clients)
211- ALL=$(ruby -ryaml -e '
211+ # --- Collect all target URIs (master + clients) from inventory
212+ ALL=" $(ruby -ryaml -e '
212213 inv = YAML.load_file("spec/fixtures/litmus_inventory.yaml")
213- puts inv.fetch("groups",[]).flat_map{|g| g.fetch("targets",[])}.map{|t| t["uri"]}.join(",")
214- ')
214+ puts inv.fetch("groups",[]).flat_map{|g| g.fetch("targets",[]) }.map{|t| t["uri"]}.join(",")
215+ ')"
215216 [[ -n "$ALL" ]] || { echo "No targets found in inventory"; exit 3; }
216217
218+ # --- Resolve and sanitize master URI for package installs
217219 MASTER='${{ steps.pe-master.outputs.master_uri }}'
218220 MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
219221
220- # Ensure agent/CLI is present (idempotent) and make a friendly symlink
221- bundle exec bolt command run \
222- "/bin/bash -lc '
223- if ! [ -x /opt/puppetlabs/bin/puppet ]; then
224- echo \"Installing puppet-agent from https://${MASTER}:8140...\" >&2
225- curl -ks https://${MASTER}:8140/packages/current/install.bash | bash || exit 1
222+ echo "Ensuring puppet CLI present (best-effort) on: $ALL"
223+ bundle exec bolt command run "/bin/bash -lc '
224+ set -Eeuo pipefail; set -o pipefail
225+ if ! command -v puppet >/dev/null 2>&1 && [ ! -x /opt/puppetlabs/bin/puppet ]; then
226+ echo \"Installing puppet-agent from https://${MASTER}:8140...\" >&2
227+ success=0
228+ for i in 1 2 3; do
229+ if curl -fsSLk https://${MASTER}:8140/packages/current/install.bash | bash; then
230+ success=1; break
231+ fi
232+ echo \"Install attempt $i failed; retrying...\" >&2
233+ sleep $((i*5))
234+ done
235+ if [ $success -eq 0 ]; then
236+ echo \"WARN: puppet-agent install failed; will continue with tarball fallback.\" >&2
226237 fi
227- ln -sf /opt/puppetlabs/bin/puppet /usr/bin/puppet || \
238+ fi
239+ # convenience symlinks if CLI exists
240+ if [ -x /opt/puppetlabs/bin/puppet ]; then
241+ ln -sf /opt/puppetlabs/bin/puppet /usr/bin/puppet || true
228242 ln -sf /opt/puppetlabs/bin/puppet /usr/local/bin/puppet || true
229- '" \
243+ fi
244+ exit 0
245+ '" \
230246 -i spec/fixtures/litmus_inventory.yaml \
231247 --targets "$ALL" \
232248 --run-as root
233249
234- # Upload & install
250+ echo "Uploading module archive to targets..."
235251 bundle exec bolt file upload "${TAR}" /root/ntp.tgz \
236252 -i spec/fixtures/litmus_inventory.yaml \
237253 --targets "$ALL"
238254
239- bundle exec bolt command run \
240- "/opt/puppetlabs/bin/puppet module install /root/ntp.tgz --force --ignore-dependencies" \
255+ echo "Installing module on targets (uses puppet if present, falls back to unpack)..."
256+ bundle exec bolt command run "/bin/bash -lc '
257+ set -Eeuo pipefail; set -o pipefail
258+ puppet_bin=\$(command -v puppet || echo /opt/puppetlabs/bin/puppet)
259+ if [ -x \"\$puppet_bin\" ]; then
260+ \"\$puppet_bin\" module install /root/ntp.tgz --force --ignore-dependencies
261+ else
262+ echo \"WARN: puppet CLI not found; unpacking module into codedir\" >&2
263+ mkdir -p /etc/puppetlabs/code/environments/production/modules
264+ tar -xzf /root/ntp.tgz -C /etc/puppetlabs/code/environments/production/modules
265+ fi
266+ '" \
241267 -i spec/fixtures/litmus_inventory.yaml \
242268 --targets "$ALL" \
243269 --run-as root
244270
245- # Verify
246- bundle exec bolt command run \
247- "/opt/puppetlabs/bin/puppet module list --tree | egrep -i '(^| )ntp( |$)'" \
271+ echo "Verifying module presence..."
272+ bundle exec bolt command run "/bin/bash -lc '
273+ set -Eeuo pipefail; set -o pipefail
274+ if command -v puppet >/dev/null 2>&1 || [ -x /opt/puppetlabs/bin/puppet ]; then
275+ puppet_bin=\$(command -v puppet || echo /opt/puppetlabs/bin/puppet)
276+ \"\$puppet_bin\" module list --tree | egrep -i \"(^| )ntp( |$)\" || true
277+ else
278+ if test -d /etc/puppetlabs/code/environments/production/modules/puppetlabs-ntp; then
279+ echo \"puppetlabs-ntp present (unpacked)\"
280+ else
281+ echo \"WARN: ntp module not found\"
282+ fi
283+ fi
284+ '" \
248285 -i spec/fixtures/litmus_inventory.yaml \
249- --targets "$ALL" || true
286+ --targets "$ALL" \
287+ --run-as root || true
250288
251289 - name : Run integration tests
252290 run : |
0 commit comments