Ensure present/latest for puppet driven package updates
[apex-tripleo-heat-templates.git] / extraconfig / tasks / yum_update.sh
1 #!/bin/bash
2
3 # A heat-config-script which runs yum update during a stack-update.
4 # Inputs:
5 #   deploy_action - yum will only be run if this is UPDATE
6 #   update_identifier - yum will only run for previously unused values of update_identifier
7 #   command - yum sub-command to run, defaults to "update"
8 #   command_arguments - yum command arguments, defaults to ""
9
10 echo "Started yum_update.sh on server $deploy_server_id at `date`"
11 echo -n "false" > $heat_outputs_path.update_managed_packages
12
13 if [[ -z "$update_identifier" ]]; then
14     echo "Not running due to unset update_identifier"
15     exit 0
16 fi
17
18 timestamp_dir=/var/lib/overcloud-yum-update
19 mkdir -p $timestamp_dir
20
21 command_arguments=${command_arguments:-}
22 # exclude upgrading packages that are handled by config management tooling
23 for exclude in $(cat /var/lib/tripleo/installed-packages/* | sort -u); do
24   command_arguments="$command_arguments --exclude $exclude"
25 done
26
27 # sanitise to remove unusual characters
28 update_identifier=${update_identifier//[^a-zA-Z0-9-_]/}
29
30 timestamp_file="$timestamp_dir/$update_identifier"
31 if [[ -a "$timestamp_file" ]]; then
32     echo "Not running for already-run timestamp \"$update_identifier\""
33     exit 0
34 fi
35 touch "$timestamp_file"
36
37 command=${command:-update}
38 full_command="yum -y $command $command_arguments"
39 echo "Running: $full_command"
40
41 result=$($full_command)
42 return_code=$?
43 echo "$result"
44 echo "yum return code: $return_code"
45
46 echo -n "true" > $heat_outputs_path.update_managed_packages
47
48 echo "Finished yum_update.sh on server $deploy_server_id at `date`"
49
50 exit $return_code