HI All,
I have written packer script to build AMI with provisioning using Ansible, I can see ec2 instance gets created, but Packer is not able to take ssh to that ec2 instance. Could you please let me know from below piece of code when I have made mistakes. Even I was triggering using GitLab CI/CD pipeline.
Code:
{
"min_packer_version": "1.8.0",
"variables": {
"build_version": "{{isotime `2006-01-02`}}"
},
"builders": [
{
"type": "amazon-ebs",
"name": "linux-soe-build-project",
"region": "{{user `region`}}",
"vpc_id": "{{user `vpc_id`}}",
"subnet_id": "{{user `subnet_id`}}",
"communicator": "ssh",
"ssh_username": "ec2-user",
"ssh_port": 22,
"ssh_keypair_name": "keypair",
"ssh_private_key_file": "/home/gitlab-runner/.ssh/keypair.pem",
"ssh_agent_auth": false,
"ssh_timeout": "10m",
"ami_name": "{{user `ami_build`}}-{{user `build_version`}}",
"ami_description": "{{user `ami_description`}}",
"instance_type": "t2.micro",
"availability_zone": "{{user `availability_zone`}}",
"security_group_id": "sg-xxxxxxxxxxxxxxx",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "base-image-amazonlinux-17-07-2022",
"root-device-type": "ebs"
},
"owners": ["xxxxxxxxxxxxxx"],
"most_recent": true
},
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_type": "gp2",
"volume_size": 8,
"delete_on_termination": true
}
],
"tags": {
"Name": "golden-image-automation",
"DeploymentType": "Auotmated",
"Environment": "Test",
"Owner": "anirb...@xyz.com"
},
"snapshot_tags": {
"Name": "snapshot-build-automated",
"DeploymentType": "Auotmated",
"Owner": "anirb...@xyz.com"
}
}
],
"provisioners": [
{
"type": "file",
"source": "./ansible",
"destination": "/tmp/ansible"
},
{
"type": "file",
"source": "./script",
"destination":"/tmp/script"
}
]
}
Error: Attached.