Packer不返回来自供应脚本的输出,而是跳过它。
封隔器脚本:
provisioner "shell" {
execute_command = "echo 'packer' | sudo -S sh -c {{ .Vars }} {{ .Path }}"
environment_vars = [
"cluster_name = ${local.cluster_name}",
"master_node = ${local.master_node}",
"security_groups" = ${local.security_groups}",
]
script = "setup.sh"
}Shell脚本:
cat << EOF | sudo tee example.yml
cluster.name: ${cluster_name}
node.name: ${master_node}
security.groups ${security_groups}
EOF日志:
==> amazon-ebs.elasticsearch: Provisioning with shell script: setup.sh
==> amazon-ebs.elasticsearch: Stopping the source instance...
amazon-ebs.elasticsearch: Stopping instance冗长日志
2022/11/17 11:11:56 packer-provisioner-shell plugin: Opening setup.sh for reading
2022/11/17 11:11:56 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:56 [DEBUG] Opening new ssh session
2022/11/17 11:11:56 packer-provisioner-shell plugin: [INFO] 1380 bytes written for 'uploadData'
2022/11/17 11:11:56 [INFO] 1380 bytes written for 'uploadData'
2022/11/17 11:11:57 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:57 [DEBUG] Starting remote scp process: scp -vt /tmp
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] Started SCP session, beginning transfers...
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] Copying input data into temporary file so we can read the length
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] scp: Uploading script_8568.sh: perms=C0644 size=1380
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] SCP session complete, closing stdin pipe.
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] Waiting for SSH session to complete.
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] scp stderr (length 32): Sink: C0644 1380 script_8568.sh
2022/11/17 11:11:58 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:58 [DEBUG] Opening new ssh session
2022/11/17 11:11:59 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:59 [DEBUG] starting remote command: chmod 0755 /tmp/script_8568.sh
2022/11/17 11:11:59 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:59 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:11:59 [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:11:59 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:11:59 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:11:59 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:59 [DEBUG] Opening new ssh session
2022/11/17 11:11:59 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:59 [DEBUG] starting remote command: echo 'packer' | sudo -S sh -c PACKER_BUILDER_TYPE='amazon-ebs' PACKER_BUILD_NAME='example' cluster_name='example-cluster' master_node='example-master_node' security_groups='example1 example2 example 3' /tmp/script_8568.sh
2022/11/17 11:12:00 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:00 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:12:00 [INFO] 0 bytes written for 'stdout'
2022/11/17 11:12:00 [INFO] 0 bytes written for 'stderr'
2022/11/17 11:12:00 [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:12:00 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:12:00 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stdout'
2022/11/17 11:12:00 packer-provisioner-shell plugin: [INFO] 0 bytes written for 'stderr'
2022/11/17 11:12:00 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:12:00 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:00 [DEBUG] Opening new ssh session
2022/11/17 11:12:00 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:00 [DEBUG] starting remote command: rm -f /tmp/script_8568.sh
2022/11/17 11:12:00 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:00 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:12:00 [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:12:00 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:12:00 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:12:00 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:00 [DEBUG] Opening new ssh session
2022/11/17 11:12:01 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:01 [DEBUG] starting remote command: rm -f
2022/11/17 11:12:01 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:12:01 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:12:01 [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:12:01 [INFO] RPC endpoint: Communicator ended with: 0
2022/11/17 11:12:01 packer-provisioner-shell plugin: [INFO] RPC client: Communicator ended with: 0
2022/11/17 11:12:01 [INFO] (telemetry) ending shell
==> amazon-ebs.elasticsearch: Stopping the source instance...没有脚本输出,我不知道execute_command可能出了什么问题,删除它也不起作用。
发布于 2022-11-29 15:43:59
根据详细日志,脚本似乎已经执行。2022/11/17 11:11:59 packer-plugin-amazon_v1.1.5_x5.0_linux_amd64 plugin: 2022/11/17 11:11:59 [DEBUG] starting remote command: echo 'packer' | sudo -S sh -c PACKER_BUILDER_TYPE='amazon-ebs' PACKER_BUILD_NAME='example' cluster_name='example-cluster' master_node='example-master_node' security_groups='example1 example2 example 3' /tmp/script_8568.sh
https://stackoverflow.com/questions/74479361
复制相似问题