Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jmalette opened this issue Aug 28, 2019 · 6 comments
Open

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

jmalette opened this issue Aug 28, 2019 · 6 comments

Comments

@jmalette
Copy link

jmalette commented Aug 28, 2019

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
Copy link
Author

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
Copy link
Contributor

This seems related to #5667.

@jmalette
Copy link
Author

#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
Copy link

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
Copy link

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
Copy link

CrimsonRot commented Jul 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants