User-data scripts is not running on my custom AMI, but working in standard Amazon linux

后端 未结 11 1366
南方客
南方客 2020-12-08 02:15

I searched a lot of topic about \"user-data script is not working\" in these few days, but until now, I haven\'t gotten any idea about my case yet, please help me to figure

11条回答
  •  借酒劲吻你
    2020-12-08 02:29

    I have also faced the same issue on Ubuntu 16.04 hvm AMI. I have raised the issue to AWS support but still I couldn't find exact reason/bug which affects it.

    But still I have something which might help you.

    Before taking AMI remove /var/lib/cloud directory (each time). Then while creating Image, set it to no-reboot.

    If these things still ain't working, you can test it further by forcing user-data to run manually. Also tailf /var/log/cloud-init-output.log for cloud-init status. It should end with something like modules:final to make your user-data run. It should not stuck on modules:config.

    sudo rm -rf /var/lib/cloud/* sudo cloud-init init sudo cloud-init modules -m final

    I don't have much idea whether above commands will work on CentOS or not. I have tested it on Ubuntu.

    In my case, I have also tried removing /var/lib/cloud directory, but still it failed to execute user-data in our scenario. But I have came up with different solution for it. What we have did is we have created script with above commands and made that script to run while system boots.

    I have added below line in /etc/rc.local to make it happen.

    sudo bash /home/ubuntu/force-user-data.sh || exit 1

    But here is the catch, it will execute the script on each boot so which will make your user-data to run on every single boot, just like #cloud-boothook. No worries, you can just tweak it by just removing the force-user-data.sh itself at the end. So your force-user-data.sh will look something like

    #!/bin/bash sudo rm -rf /var/lib/cloud/* sudo cloud-init init sudo cloud-init modules -m final sudo rm -f /home/ubuntu/force-user-data.sh exit 0

    I will appreciate if someone can put some lights on why it is unable to execute the user-data.

提交回复
热议问题