Skip to content

Commit 3841645

Browse files
committed
MODULES-10763 Do not report apt-get update as a change
1 parent 0a23900 commit 3841645

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

manifests/update.pp

+14-2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,25 @@
5656
} else {
5757
$_refresh = true
5858
}
59+
# We perform the update in an `unless` clause of the exec, and
60+
# return true only if the `/var/cache/apt/pkgcache.bin` file changed.
61+
# This ensures that Puppet does not report a change if the
62+
# update command had no effect. See MODULES-10763 for discussion.
63+
$apt_update_unless = epp(
64+
'apt/update_had_no_effect.sh.epp',
65+
'provider' => $apt::provider,
66+
'timeout' => $apt::_update['timeout'],
67+
'tries' => $apt::_update['tries'],
68+
)
5969
exec { 'apt_update':
60-
command => "${apt::provider} update",
70+
command => "echo ${apt::provider} updated the package cache.",
6171
loglevel => $apt::_update['loglevel'],
6272
logoutput => 'on_failure',
73+
path => '/bin:/sbin:/usr/bin:/usr/sbin',
74+
provider => shell,
6375
refreshonly => $_refresh,
6476
timeout => $apt::_update['timeout'],
6577
tries => $apt::_update['tries'],
66-
try_sleep => 1,
78+
unless => $apt_update_unless,
6779
}
6880
}

templates/update_had_no_effect.sh.epp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<%- |
2+
String $provider = 'apt',
3+
Integer $timeout = 30,
4+
Integer $tries = 1,
5+
| -%>
6+
7+
EVAL="$(mktemp)" || EVAL=/tmp/aptdir
8+
apt-config shell DIR Dir::Cache > "$EVAL" && . "$EVAL"
9+
[ "$DIR" ] || DIR='var/cache/apt'
10+
cd "/$DIR" || exit 0
11+
export TMPDIR="/$DIR"
12+
apt-config shell CUR DIR::Cache::pkgcache >"$EVAL" && . "$EVAL"
13+
[ "$CUR" ] || CUR=pkgcache.bin
14+
OLD="$(mktemp)" || OLD="/${DIR}/${CUR}.old"
15+
rm -f "$EVAL"
16+
[ -e "$CUR" ] || touch "$CUR"
17+
ln -f "$CUR" "$OLD"
18+
TRIES=<%= $tries %>
19+
while true; do
20+
if timeout 1 true; then
21+
timeout <%= $timeout %>m <%= $provider %> update && break
22+
else
23+
<%= $provider %> update && break
24+
fi
25+
[ $TRIES -le 1 ] && break
26+
sleep 1
27+
TRIES=$(( TRIES - 1 ))
28+
done
29+
SAME=1
30+
[ -e "$CUR" ] || touch "$CUR"
31+
cmp "$CUR" "$OLD" && SAME=0
32+
rm -f "$OLD"
33+
exit $SAME

0 commit comments

Comments
 (0)