AWS user_data with Packer

假如想象 提交于 2019-12-04 03:10:31

Rereading this I think maybe you misunderstood how user-data scripts work with Packer.

user_data is provided when the EC2 instance is launched by Packer. This instance is in the end, after provisioning snapshoted and saved as an AMI.

When you launch new instances from the created AMI it doesn't have the same user-data, it gets the user-data you specify when launching this new instance.

The effect of the initial (defined in your template) user-data might or might not be present in the new instance depending if the change was persisted in the AMI.

As pointed out by Rickard von Essen the answer was to copy my script to /var/lib/cloud/scripts/per-instance which would execute my script on every instance launched from this AMI.

Alternately you can put your script in /var/lib/cloud/scripts/per-boot if you needed this to happen each time the instance boots.

In my case since I wanted to register the instance with a 3rd party service I only had it execute once per instance creation.

Uploading to /var/lib/cloud/scripts/* will work, but it depends on how you want your images built. Do you need to be able to spin up an instance quickly?

The best solution would be to us Packer provisioners. Provisioners are used to install and configure the machine image after booting by using ansible/salt/puppet/cheff/shell scripts etc, you can provision your image with what ever you need. That way you are not tied down to having to provision deps on each instance launch, which can cause some issues (think intermittent network issues/failures, which could cause some deps not to be installed)

The provisioners for packer are third party u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!