hashicorp 加壳器配置错误,加壳器验证命令

问题描述 投票:0回答:0

Packer代码如下

variable "ami_id" {
  type    = string
  default = "ami-xxxxxxxxxx"
}
variable "environment" {
  type    = string
  default = "DEMO"
}
variable "ec2_size" {
  type    = string
  default = "t2.micro"
}

variable "ssh-user" {
  type    = string
  default = "ec2-user"
}

variable "app_name" {
  type    = string
  default = "Test App"
}

locals {
  app_name = "Test App"
}
source "amazon-ebs" "rhel8" {
  ami_name      = "PACKER-POC-${local.app_name}"
  instance_type = "${var.ec2_size}"
  #region        = "${var.region}"
  source_ami   = "${var.ami_id}"
  ssh_username = "${var.ssh-user}"
  vpc_id       = "vpc-xxxxxxxxxx"
  subnet_id    = "subnet-xxxxxxxxxx"
  tags = {
    Env  = "${var.environment}"
    Name = "PACKER-${var.environment}-${var.app_name}"
  }
}
build {
  sources = ["source.amazon-ebs.rhel8"]

  provisioner "shell" {
    script = "mkdir -p /tmp/temp123/"
  }

  provisioner "file" {
    source      = "user-data.sh"
    destination = "/tmp/temp123/user-data.sh"
  }

  provisioner "shell" {
    inline = [
      "mkdir -p /tmp/temp123",
      "chmod 755 /tmp/temp123/user-data.sh",
      "echo Installing Updates",
      "sudo apt-get update",
      "sudo apt-get upgrade -y",
      "sudo apt-get install -y nginx"
    ]
  }
  provisioner "shell" {
    script = "/tmp/temp123/user-data.sh"
  }

  post-processor "shell-local" {
    inline = ["echo Finished with the Test Application Installation"]
  }
}

但是,我收到如下错误:

packer validate app.pkr.hcl
Error: Failed preparing provisioner-block "shell" ""

  on app.pkr.hcl line 43:
  (source code not available)

1 error(s) occurred:

* Bad script 'mkdir -p /tmp/temp123/': stat mkdir -p /tmp/temp123/: no such file
or directory

Error: Failed preparing provisioner-block "shell" ""

  on asm.pkr.hcl line 62:
  (source code not available)

1 error(s) occurred:

* Bad script '/tmp/temp123/user-data.sh': stat /tmp/temp123/user-data.sh: no
such file or directory

要完成的目标:我想启动 EC2 并执行用户数据 shell 脚本,然后创建一个 AMI。

我很想知道我做错了什么,因为我希望我的应用程序工作负载被烘焙到 AMI 中,这样我就可以用它来启动 EC2s

我编写了 app.pkr.hcl 代码并执行了 packer validate 命令,但它出错了。

加壳配置文件和 shell 脚本在同一个文件夹中

ls -larth
total 24
-rwxr-xr-x@  1 testuser  staff   6.5K Mar 10 11:21 user-data.sh
drwxr-xr-x  10 testuser  staff   320B Mar 10 21:08 ..
drwxr-xr-x   4 testuser  staff   128B Mar 12 13:56 .
-rw-r--r--   1 testuser  staff   1.4K Mar 13 14:00 app.pkr.hcl
amazon-ec2 hashicorp-packer
© www.soinside.com 2019 - 2024. All rights reserved.