1
我試圖從打包模板創建一個GCE圖像。如何在包裝器中爲GCE指定元數據?
下面是我用於此目的的部分。
"builders": [
...
{
"type": "googlecompute",
"account_file": "foo",
"project_id": "bar",
"source_image": "centos-6-v20160711",
"zone": "us-central1-a",
"instance_name": "packer-building-image-centos6-baz",
"machine_type": "n1-standard-1",
"image_name": "centos6-some-box-name",
"ssh_username": "my_username",
"metadata": {
"startup-script-log-dest": "/opt/script.log",
"startup-script": "/opt/startup.sh",
"some_other_custom_metadata_key": "some_value"
},
"ssh_pty": true
}
],
...
我也創建了所需的文件。這裏是沒有的「元數據」字段部分
"provisioners": [
...
{
"type": "file",
"source": "{{user `files_path`}}/startup.sh",
"destination": "/opt/startup.sh"
},
...
{
"type": "shell",
"execute_command": "sudo sh '{{.Path}}'",
"inline": [
...
"chmod ugo+x /opt/startup.sh"
]
}
...
一切對我的作品。我可以使用提供的參數創建圖像/實例。但是當我嘗試從圖像中創建實例時,找不到提供的元數據,並且無法運行我的啓動腳本,設置日誌文件和其他自定義元數據。 這裏是我使用https://www.packer.io/docs/builders/googlecompute.html#metadata的來源。
任何建議都會有幫助。
在此先感謝