diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh index 6791ceb639..434a0adbee 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh @@ -1,22 +1,29 @@ - #!/bin/bash +#!/bin/bash +set -u export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin containerIds=$(docker ps -q) +commonPackages="gnupg fakeroot" +fedoraPackages="procps-ng hostname shared-mime-info" +debianPackages="" +alpinePackages="" + for container in $containerIds do OS=$(docker exec -it $container sh -c "cat /etc/os-release" | head -n 1) - if [[ $OS =~ "CentOS" || $OS =~ "Fedora" || $OS=~ "Red Hat Enterprise Linux" ]]; then - installCommand="yum -y update" - elif [[ $OS =~ "Ubuntu" || $OS =~ "Debian" ]]; then - installCommand="apt-get update && apt-get -y upgrade" - elif [[ $OS =~ "Alpine" ]]; then - installCommand="apk update && apk upgrade" + if [[ "$OS" == *"CentOS"* ]] || [[ "$OS" == *"Fedora"* ]] || [[ "$OS" == *"Red Hat Enterprise Linux"* ]]; then + installCommand="yum -y update && yum -y install $commonPackages $fedoraPackages" + elif [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then + installCommand="apt-get update && apt-get -y upgrade && apt-get -y install $commonPackages $debianPackages" + elif [[ "$OS" == *"Alpine"* ]]; then + installCommand="apk update && apk upgrade && apk --update add $commonPackages $alpinePackages" else echo "Unrecognised OS, skipping package update" continue fi echo "Updating packages for container $container" + echo "Running $installCommand" docker exec -it $container sh -c "$installCommand" echo "==============================================" done diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml index 1e83462c9a..a44b457739 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml @@ -245,10 +245,10 @@ regexp: kernel_core_pattern line: kernel.core_pattern=core.%p -- name: Copy updatepackages.sh script to remote cron.daily directory - copy: - src: scripts/updatepackages.sh - dest: /etc/cron.daily/updatepackages.sh - owner: root - group: root - mode: +x +- name: Run updatePackage.sh script + script: scripts/updatepackages.sh + args: + executable: bash + tags: + - updateContainers + - never