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

Inline shell triggers don't recognize IO redirection #10674

Closed
anasbouzid opened this issue Feb 16, 2019 · 3 comments
Closed

Inline shell triggers don't recognize IO redirection #10674

anasbouzid opened this issue Feb 16, 2019 · 3 comments

Comments

@anasbouzid
Copy link

On triggers, I/O redirection doesn't work with the inline shell setting, using the path shell setting works normally.

Vagrant version

2.2.3

Host operating system

Ubuntu 16.04

Guest operating system

Ubuntu 18.04

Vagrantfile

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/bionic64"

  config.trigger.before :up do |trigger|
    trigger.run = {
      inline: "date >> outfile"
    }
  end
end

Debug output

https://gist.github.com/anasbouzid/e1144379ee8213c63d6370295234b053

Expected behavior

Append current date to outfile

Actual behavior

fails:

    default: /bin/date: extra operand ‘outfile’
    default: Try '/bin/date --help' for more information.
==> default: Trigger run failed

Steps to reproduce

Run vagrant up

@briancain
Copy link
Member

Hey there @anasbouzid - This is actually something I've been meaning to document. When you use the run option with inline scripts, you are executing a shell subprocess, not a bash session. You are not the first person to run into this.....IO redirection with that operator is actually something within bash, so you'll want to do something like this to execute your script in bash:

 config.trigger.after :up do |t|
      t.run = {inline: "/bin/bash -c 'date >> outfile'"}
end
brian@localghost:vagrant-sandbox % be vagrant up bork                                                    ±[●][master]
Bringing machine 'bork' up with 'virtualbox' provider...
==> bork: Checking if box 'bento/ubuntu-18.04' version '201812.27.0' is up to date...
==> bork: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> bork: flag to force provisioning. Provisioners marked to run always will still run.
==> bork: Running action triggers after up ...
==> bork: Running trigger...
    bork: Running local: Inline script
    bork: /bin/bash -c 'date >> outfile.txt'
brian@localghost:vagrant-sandbox % ls outfile.txt                                                       ±[●●][master]
outfile.txt
brian@localghost:vagrant-sandbox % cat outfile.txt                                                      ±[●●][master]
Thu Feb 21 11:22:43 PST 2019

@briancain briancain added this to the 2.2.4 milestone Feb 21, 2019
@anasbouzid
Copy link
Author

Thanks for your help, much appreciated.

@ghost
Copy link

ghost commented Mar 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashicorp hashicorp locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants