1

i am trying my hands on packer , i am new to it .

This is my following is the packer code. I chose inline shell because i am not greatly aware of any configure management tool like ansible or chef .

{
    "variables": {
      "aws_access_key": "",
      "aws_secret_key": ""
    },
    "builders": [
      {
        "type": "amazon-ebs",
        "profile":"sumanthdev",
        "region": "me-south-1",
        "source_ami_filter": {
          "filters": {
            "virtualization-type": "hvm",
            "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
            "root-device-type": "ebs"
          },
          "owners": ["099720109477"],
          "most_recent": true
        },
        "instance_type": "t3.micro",
        "ssh_username": "ubuntu",
        "ami_name": "packer-example {{timestamp}}"
      }
    ],
    "provisioners": [
        {
          "type": "shell",
          "inline": [
            "sleep 30",
            "sudo su",
            "apt-get update",
            "apt-get install git -y ",
            "sleep 30",
            "apt-get install nodejs",
            "apt-get install npm",
            "sleep 30",
            "apt-get update",
            "wget https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb",
            "dpkg -i packages-microsoft-prod.deb",
            "apt-get update",
            "apt-get install dotnet-sdk-3.1",
            "sleep 30",
            "apt-get install apache2 -y"
          ]
        }
      ]
  }

I am able to validate the code with no error . i am also sure that my inline script is the one which is causing some errors. this is the complete output with error code .

amazon-ebs: Prevalidating any provided VPC information
==> amazon-ebs: Prevalidating AMI Name: packer-example 1592360602
    amazon-ebs: Found Image ID: ami-0054116010789ce83
==> amazon-ebs: Creating temporary keypair: packer_5ee97e9a-a51f-e95f-bfd2-6a2c174b2f1d
==> amazon-ebs: Creating temporary security group for this instance: packer_5ee97e9e-9309-a6a6-9310-3eac8ad01f98
==> amazon-ebs: Authorizing access to port 22 from [0.0.0.0/0] in the temporary security groups...
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Adding tags to source instance
    amazon-ebs: Adding tag: "Name": "Packer Builder"
    amazon-ebs: Instance ID: i-0158241c9618fa95d
==> amazon-ebs: Waiting for instance (i-0158241c9618fa95d) to become ready...
==> amazon-ebs: Using ssh communicator to connect: 157.175.95.205
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Provisioning with shell script: C:\Users\asus\AppData\Local\Temp\packer-shell769069235
    amazon-ebs: Reading package lists...
==> amazon-ebs: W: chmod 0700 of directory /var/lib/apt/lists/partial failed - SetupAPTPartialDirectory (1: Operation not permitted)
==> amazon-ebs: E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
==> amazon-ebs: E: Unable to lock directory /var/lib/apt/lists/
==> amazon-ebs: W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
==> amazon-ebs: W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Script exited with non-zero exit status: 100.Allowed exit codes are: [0]

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Script exited with non-zero exit status: 100.Allowed exit codes are: [0]

==> Builds finished but no artifacts were created.

Could you please guide me through this?

sumanth shetty
  • 1,851
  • 5
  • 24
  • 57
  • 1
    To run with sudo with the shell provisioner you need to set the [`execute_command`](https://www.packer.io/docs/provisioners/shell#sudo-example) – ydaetskcoR Jun 17 '20 at 08:09

0 Answers0