Trying to create new AMI using amazon-ebssurrogate with source AMI snapshot that is partitioned with LVM

Hello All,

I have been experiencing an odd issue using the “amazon-ebssurrogate” builder. The source AMI I am using is partitioned with LVM as below:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 30G 0 disk
├─xvda1 202:1 0 1M 0 part
├─xvda2 202:2 0 10G 0 part /
└─xvda3 202:3 0 20G 0 part
├─vg_root-lv_home 253:0 0 5G 0 lvm /home
├─vg_root-lv_var 253:1 0 8G 0 lvm /var
├─vg_root-lv_varlog 253:2 0 4G 0 lvm /var/log
├─vg_root-lv_vartmp 253:3 0 2G 0 lvm /var/tmp
└─vg_root-lv_varlogaudit 253:4 0 1020M 0 lvm /var/log/audit

My Packer script runs a “shell” provisioner at the very end that creates 4 IDs with these commands:

useradd -m -u 533 -g ansible ansible
useradd -m -u 526 uatagnt
useradd -m -u 510 -g idadmin idadmin
useradd -m -u 519 -g wasadm wasadm

The issue is that an instance created from the Packer script made AMI has the IDs created … but their home directories do not exist. The -m in the commands above “should” have created home directories for each ID.

I thought perhaps it was a timing issues … like it was running the ID provisioner script before the LVM FSs were mounted. So I put a “pause_before_connecting” for 1 minute … but it still didn’t work.

Is there something I am missing? Here is the source and build section of my Packer script. Any help would be greatly appreciated:

source "amazon-ebssurrogate" "image" {
  region = local.region
  ssh_username = "ec2-user"
  instance_type = "t2.micro"
  source_ami = local.gold_image
  ami_name = local.name
  ami_virtualization_type = "hvm"

  launch_block_device_mappings {
    device_name = "/dev/sdb"
    snapshot_id = "snap-0487bf5911ccfd323"
    delete_on_termination = false
    volume_type = "gp2"
  }

  ami_root_device {
    source_device_name = "/dev/sdb"
    device_name = "/dev/sda1"
    delete_on_termination = false
    volume_size = 30
    volume_type = "gp2"
  }
  pause_before_connecting = "1m"
}

build {
  name = "${local.name}-amazon-ebssurrogate"
  sources = [
    "source.amazon-ebssurrogate.image",
  ]

  provisioner "shell" {
    inline = [
      "echo '${local.name}'> ~/ami_name.txt",
    ]
  }

  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo {{ .Path }}"
    script          = "./filesystem.sh"
  }

  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo {{ .Path }}"
    script          = "./packages.sh"
  }

  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo {{ .Path }}"
    script          = "./csd_compliance.sh"
  }

  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo {{ .Path }}"
    script          = "./ids.sh"
  }
}

Thank you,

Thecoolio2