I am creating an AWS EC2 t2.micro and using the below user data. I added the condition to check for the presence of the "BootstrapCompleted " file and run updates AFTER that.
#!/bin/bash
while [ ! -f /tmp/BootstrapCompleted ]
do
sleep 300
done
echo "file found" >> /tmp/ameya.log
echo -e "Ameya is going mad" >> /tmp/ameya.log
sleep 120
yum update -y >> /tmp/ameya.log
echo -e "\n My Sanity is restored" >> /tmp/ameya.log
However, when I do SSH to the VM and run
yum update -y
It runs the updates meaning they are not installed with User Data.
P.S: As per Amir, I checked the log file
cat /var/log/cloud-init-output.log
I see some issue here. Last few lines output as below.
Cloud-init v. 22.1-5.el8 running 'modules:config' at Thu, 23 Feb 2023 01:59:01 +0000. Up 101.14 seconds.
Errors during downloading metadata for repository 'epel':
- Curl error (6): Couldn't resolve host name for https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/repodata/repomd.xml [Could not resolve host: dl.fedoraproject.org]
Error: Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Cloud-init v. 22.1-5.el8 running 'modules:final' at Thu, 23 Feb 2023 02:00:10 +0000. Up 170.00 seconds.
Cloud-init v. 22.1-5.el8 finished at Thu, 23 Feb 2023 02:02:12 +0000. Datasource DataSourceEc2Local. Up 291.76 seconds
I note that ameya.log is created as per below.
[root@ANL62600251 ~]# cat /tmp/ameya.log
file found
Ameya is going mad
Extra Packages for Enterprise Linux 8 - x86_64 0.0 B/s | 0 B 00:00
My Sanity is restored
I now run
yum update
Interesting observation is
yum update
Extra Packages for Enterprise Linux 8 - x86_64 6.5 kB/s | 4.7 kB 00:00
This tells me that, when yum update was running it had no internet connection?