hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.48k stars 9.51k forks source link

remote-exec fails when chmod not there #5667

Open davidbailey opened 8 years ago

davidbailey commented 8 years ago

The remote-exec provisioner requires the target host to have chmod in its path. If the default shell is not sh, bash, etc. it will fail. Is there a way to directly run commands via this provisioner in the target shell? Or is it possible to specify another shell?

For a little more background, I am trying to run configuration commands on an F5 BigIP device. However, the default shell of the device (in /etc/password) is the configuration shell, tmsh. This shell does not have normal Unix commands. It is possible to run bash by simply typing bash in tmsh, but this is not currently possible in Terraform.

Relevant line of code: https://github.com/hashicorp/terraform/blob/cf98cbc9adc6df1cabf73ba9689574bbb3905972/communicator/ssh/communicator.go#L281

Logs: aws_instance.f5a (remote-exec): Connected! 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 opening new ssh session 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 Starting remote scp process: scp -vt /tmp 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 Started SCP session, beginning transfers... 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 Copying input data into temporary file so we can read the length 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 Beginning file upload... 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 SCP session complete, closing stdin pipe. 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 Waiting for SSH session to complete. 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 scp stderr (length 39): Sink: C0644 58 terraform_1298498081.sh 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 opening new ssh session 2016/03/11 15:40:26 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:26 starting remote command: chmod 0777 /tmp/terraform_1298498081.sh 2016/03/11 15:40:29 [DEBUG] vertex provider.aws (close), waiting for: aws_route53_record.f5a 2016/03/11 15:40:29 [DEBUG] vertex root, waiting for: provider.aws (close) 2016/03/11 15:40:29 [DEBUG] vertex provisioner.remote-exec (close), waiting for: aws_instance.f5a 2016/03/11 15:40:29 [DEBUG] vertex aws_route53_record.f5a, waiting for: aws_instance.f5a 2016/03/11 15:40:34 [DEBUG] vertex aws_route53_record.f5a, waiting for: aws_instance.f5a 2016/03/11 15:40:34 [DEBUG] vertex root, waiting for: provider.aws (close) 2016/03/11 15:40:34 [DEBUG] vertex provisioner.remote-exec (close), waiting for: aws_instance.f5a 2016/03/11 15:40:34 [DEBUG] vertex provider.aws (close), waiting for: aws_route53_record.f5a 2016/03/11 15:40:39 [DEBUG] vertex provider.aws (close), waiting for: aws_route53_record.f5a 2016/03/11 15:40:39 [DEBUG] vertex root, waiting for: provider.aws (close) 2016/03/11 15:40:39 [DEBUG] vertex aws_route53_record.f5a, waiting for: aws_instance.f5a 2016/03/11 15:40:39 [DEBUG] vertex provisioner.remote-exec (close), waiting for: aws_instance.f5a 2016/03/11 15:40:44 [DEBUG] vertex root, waiting for: provider.aws (close) 2016/03/11 15:40:44 [DEBUG] vertex aws_route53_record.f5a, waiting for: aws_instance.f5a 2016/03/11 15:40:44 [DEBUG] vertex provider.aws (close), waiting for: aws_route53_record.f5a 2016/03/11 15:40:44 [DEBUG] vertex provisioner.remote-exec (close), waiting for: aws_instance.f5a 2016/03/11 15:40:49 [DEBUG] vertex provisioner.remote-exec (close), waiting for: aws_instance.f5a 2016/03/11 15:40:49 [DEBUG] vertex aws_route53_record.f5a, waiting for: aws_instance.f5a 2016/03/11 15:40:49 [DEBUG] vertex provider.aws (close), waiting for: aws_route53_record.f5a 2016/03/11 15:40:49 [DEBUG] vertex root, waiting for: provider.aws (close) 2016/03/11 15:40:49 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:49 remote command exited with '1': chmod 0777 /tmp/terraform_1298498081.sh 2016/03/11 15:40:49 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:49 Retryable error: Failed to upload script: Error chmodding script file to 0777 in remote machine 1: Cannot connect to mcpd. Your preferences and aliases will not be available until it comes back up. 2016/03/11 15:40:49 [DEBUG] terraform-provisioner-remote-exec: Syntax Error: unexpected argument "chmod" 2016/03/11 15:40:49 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:52 [DEBUG] terraform-provisioner-remote-exec: 2016/03/11 15:40:52 Retryable error: Failed to upload script: Error reading script: EOF

ksanghavi commented 6 years ago

I ended up running my remote command as a local command.

  provisioner "local-exec" {
    command = "ssh <user>@${aws_instance.bigip1.private_ip} load /sys config file <file>"
  }
ArtiomL commented 6 years ago

+1

lmayorga1980 commented 5 years ago

:+1: