So I'm trying to use Packer to create an AWS image and specify some user data via user_data_file. The contents of this file needs to be run when the instance boots as it will be unique each time. I can't bake this into the AMI.
Using packer I have the following:
{
"variables": {
"ami_name": ""
},
"builders": [
{
"type": "amazon-ebs",
"region": "us-east-1",
"source_ami": "ami-c8580bdf",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "{{ user `ami_name` }}-{{ isotime | clean_ami_name }}",
"user_data_file": "user_data.sh",
"tags": {
"os_version": "ubuntu",
"built_by": "packer",
"build_on": "{{ isotime | clean_ami_name }}",
"Name": "{{ user `ami_name` }}"
}
}],
"provisioners": [
{
"type": "ansible",
"playbook_file": "playbook.yml",
"user": "ubuntu"
}]
}
The contents of my user_data shell script are just a few basic config lines for a package that was installed via the ansible scripts that were run in the provisioners step. Watching the output of Packer I can confirm that the ansible scripts all run.
Packer completes and creates the AMI, but the user data piece is never executed. No record of it exists in resulting image. There is no /userdata.log file and /var/lib/cloud/instance/user-data.txt
is empty I feel like I missing something basic as this should be a very simple thing to do with Packer.
user_data.sh
file. – Ginglymus/var/log/cloud-init-output.log
and/var/log/cloud-init.log
. – Ginglymus/var/lib/cloud/scripts/per-instance
and it isn't run? for a test you should put something very basic in there and prove that it works. following the direction I got on this issue I was able to have my Instance boot and execute the scripts in that directory – Ayurveda