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.37k stars 9.49k forks source link

Provider remote-exec generating error Process exited with status 126 #22633

Open jmalette opened 5 years ago

jmalette commented 5 years ago

Terraform Version

Terraform v0.12.7
+ provider.aws v2.23.0
+ provider.local v1.3.0
+ provider.tls v2.0.1

Terraform Configuration Files

resource "aws_instance" "TEST_lnx_nodes" {
  ami           = "${data.aws_ami.stack_ami.id}"
  instance_type = "t2.micro"
  key_name     = "${aws_key_pair.generated_key.key_name}" 

  subnet_id = "${sort(data.aws_subnet_ids.subnet_private.ids)[0]}"
  count = 2

  tags = {
    Name = "${format("${local.stack_instance_name}-lnx-%03d", count.index + 1)}" 
  }

  connection {
    type     = "ssh"
    user = "ec2-user"
    private_key = "${file(~/.ssh/${aws_key_pair.generated_key.key_name}.pem")}"
    host = self.private_ip
    agent = true
  }

  provisioner "remote-exec" {
    inline = [
      "sudo echo https_proxy=http://myproxy:myproxyport >> /etc/environment"
    ]
  }
}

Debug Output

N/A

Crash Output

N/A

Expected Behavior

terraform execute remote-exec and add that proxy entry to the environment file

Actual Behavior

I get an error - Process exited with status 126

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

It looks like when I use inline for remote-exec you are defaulting to creating the script in /tmp and on my aws ec2 instance., /tmp is mounted as a noexec mount so this will always fail. Any ability to enable this to use the connection user's home directory?

References

jmalette commented 5 years ago

BTW - after some troubleshooting, it looks like when I use the inline argument it will always create the script in /tmp and on my ec2 instance /tmp is mounted as noexec so this will always fail. can I enable this to use the connection user home directory?

hashibot commented 5 years ago

This seems related to #5667.

jmalette commented 5 years ago

5667

No, I don't think they are related. My problem is a little different as it's simply trying to execute a script from a folder that is located on a drive mounted with noexec on.

jiriprochazka commented 4 years ago

Hi, we're facing the same issue. It's quite common to have noexec flag on /tmp partition. We'd appreciate if the path was either configurable or changed.

For example Ansible uses as default path for storing executed scripts ~/.ansible/tmp/.

mohitwasnik132 commented 2 years ago

I am still getting,

 ╷
│ Error: remote-exec provisioner error
│
│   with null_resource.setup,
│   on main.tf line 59, in resource "null_resource" "setup":
│   59:   provisioner "remote-exec" {
│
│ error executing "/tmp/terraform_1227397609.sh": Process exited with status  1

I defined connection, copy, execute details on a "null resource" but still failing on terraform apply

Is there a way to change the location of terraform*.sh

CrimsonRot commented 2 years ago

We are running into the same problem.

Error: error executing "/tmp/terraform_1041217423.sh": Process exited with status 126

` provisioner "remote-exec" { inline = ["echo test > test.log"]

connection {
  host        = self.ipv4_address
  type        = "ssh"
  user        = "root"
  private_key = ***
}

}`

the "default" remote_exec directory /tmp is non executable A feature to change the default remote_exec directory would be awesome.