2016-11-24 15 views
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的來源。

任何建議都會有幫助。

在此先感謝

回答

0

的元數據標籤startup-script應包含實際工作腳本不是一個路徑。供應商在啓動腳本執行後(至少啓動)運行。

改爲在Packer中使用startup_script_file並提供啓動腳本的路徑。

相關問題