【问题标题】:Packer build .json file for Linux image creation-Builds finished but no artifacts were created用于 Linux 映像创建的 Packer 构建 .json 文件 - 构建已完成,但未创建工件
【发布时间】:2022-08-21 18:31:02
【问题描述】:

我在 windows powershell 中执行了下面的 packer.json 文件来创建一个 Linux 映像

{
    \"builders\": [{
        \"type\": \"azure-arm\",
        
        \"client_id\": \"fb61f35d-99c5-43f8-9444-f4a3b96fd1f0\",
        \"client_secret\": \"DV-8Q~CJCeAfsc.WBm5eJ5ItVdcqnUebd3zhJb-o\",
        \"tenant_id\": \"67b304ff-0032-477b-b33f-c7a9de6ab0a5\",
        \"subscription_id\": \"315c9c99-62bc-42ff-bd23-d85a808a5609\",
        
    \"managed_image_name\": \"MyUbuntuImage\",
    \"managed_image_resource_group_name\": \"newgroup\",
    
    \"os_type\": \"Linux\",
    \"image_publisher\": \"Canonical\",
    \"image_offer\": \"UbuntuServer\",
    \"image_sku\": \"16.04-LTS\",
    
    \"location\": \"eastus\",
    \"vm_size\": \"standard_B1ms\"
}],
\"provisioners\":[{
    \"execute_command\": \"chmod +x {{ .path }}; {{ .Vars }} sudo -E sh \'{{ .path }}\'\",
    \"inline\": [
    \"apt-get update\",
    \"apt-get install nginx -y\",
    \"apt-get install stress -y\",
    \"systemct1 enable nginx\",
    \"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync\"
    ],
    \"inline_shebang\": \"/bin/sh -x\",
    \"type\": \"shell\"
    }]
    }

一切都已创建,正确删除。但是,不会创建图像。以下是powershell的最后几行-

某些构建未成功完成并出现错误: --> azure-arm:脚本以非零退出状态退出:1。允许的退出代码为:[0]

==> 构建完成但没有创建工件。

我正在使用 packer_1.8.3_windows_amd64 版本

    标签: azure powershell packer


    【解决方案1】:

    错误消息通常表示它无法访问服务器或我们正在传递错误的值.

    解决问题的方法

    如果你设置“use_env_var_file”:真你必须使用执行命令

     "execute_command": "chmod +x {{.Path}}; . {{.EnvVarFile}} && {{.Path}} sudo -E sh '{{ .path }}'"
    

    如果你设置“use_env_var_file”:假您可以使用与使用相同的方法。

     "execute_command": "chmod +x {{ .path }}; {{ .Vars }} sudo -E sh '{{ .path }}'",
    

    由于 Packer 用户使用不同的外壳,可能会发生此问题。为避免这种情况,您可以使用有效退出代码在供应商中。正如R. Barrett 在他的回答中提到的

    "provisioners":[{
        valid_exit_codes = [
              "0",
              "1",
              "2"
            ]
         "execute_command": "chmod +x {{ .path }}; {{ .Vars }} sudo -E sh '{{ .path }}'",
        "inline": [
            .....
    

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 2011-03-23
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 2011-07-18
      相关资源
      最近更新 更多