首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Packer跳过shell脚本,execute_command有问题吗?

Packer跳过shell脚本,execute_command有问题吗?
EN

Stack Overflow用户
提问于 2022-11-17 17:02:06
回答 1查看 28关注 0票数 0

Packer不返回来自供应脚本的输出,而是跳过它。

封隔器脚本:

代码语言:javascript
复制
  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脚本:

代码语言:javascript
复制
cat << EOF | sudo tee example.yml
cluster.name: ${cluster_name}
node.name: ${master_node}
security.groups ${security_groups}
EOF

日志:

代码语言:javascript
复制
==> amazon-ebs.elasticsearch: Provisioning with shell script: setup.sh
==> amazon-ebs.elasticsearch: Stopping the source instance...
    amazon-ebs.elasticsearch: Stopping instance

冗长日志

代码语言:javascript
复制
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可能出了什么问题,删除它也不起作用。

EN

回答 1

Stack Overflow用户

发布于 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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74479361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档