I just read you tried vagrant-triggers, and got past the error with ./script
sorry for that Alvaro. On Tue, Jun 16, 2015 at 1:22 PM, Alvaro Miranda Aguilera <[email protected]> wrote: > Hello, > > Have a look at vagrant-triggers > > you can define scripts how I told youd, and vagrant-triggers will run > them at specific events.. pre-creation, pre-boot, etc > > > > On Tue, Jun 16, 2015 at 7:31 AM, Donavan Kienenberger > <[email protected]> wrote: >> I should mention these commands are being run before the box is up, meaning >> they are running on the system that vagrant is on, not on the box. I have >> successfully run other commands that are not using quotes, so I can verify >> that this issue seems to be specific to "run" not properly handling a >> command that is trying to pass quotes. >> >> I can't avoid using the quotes especially in regular expression as they are >> key in the data search. The single quote is needed for the sed command to >> process the search and replace parameters. However I did find a cleaner >> method using hex escapes run command still fails. So there is a coding issue >> with the run command and quotes that should be fixed. >> >> run "/bin/sed -i -r \x27s/\x22groups\x22: \[$/\x22groups\x22: \[\x5cn >> \x22ATESTA_admin\x22,/\x27 /root/chef-repo/data_bags/users/vagrant.json" >> >> outputs: >> >> ==> default: Executing command "/bin/sed -i -r s/"groups": [$/"groups": [n >> "ATESTA_admin",/ /root/chef-repo/data_bags/users/vagrant.json"... >> ==> default: /bin/sed: -e expression #1, char 47: unterminated `s' command >> ==> default: Command execution finished. >> The command "/bin/sed -i -r 's/"groups": [$/"groups": [\n >> "ATESTA_admin",/' /root/chef-repo/data_bags/users/vagrant.json" returned a >> failed exit code. >> >> >> I did solve the "No such file or directory" error when trying to run the >> commands in a bash script. Unlike the config.vm.provision command, it turned >> out that vagrant-triggers doesn't "auto-look" at the current directory so >> you have to specify a path to your script. So I just needed to modify it to: >> "./prebootstrap.sh" The sed command with quotes worked fine in the bash >> script. So I now have a useable solution. >> >> >> On Friday, June 12, 2015 at 10:49:05 PM UTC-8, Alvaro Miranda Aguilera >> wrote: >>> >>> Hello >>> >>> Try to define the command, and avoid the nigthmare of escapes, quotes, etc >>> >>> use something like this: >>> >>> $script = <<SCRIPT >>> echo I am provisioning... >>> date > /etc/vagrant_provisioned_at >>> SCRIPT >>> >>> Vagrant.configure("2") do |config| >>> config.vm.provision "shell", inline: $script >>> end >>> >>> >>> >>> On Sat, Jun 13, 2015 at 10:27 AM, Donavan Kienenberger >>> <[email protected]> wrote: >>> > OS Centos 6 >>> > INFO global: Vagrant version: 1.7.2 >>> > INFO global: Ruby version: 2.0.0 >>> > INFO global: RubyGems version: 2.0.14 >>> > INFO global: - vagrant-triggers = 0.5.0 >>> > >>> > So I have a problem with running a command in vagrant-triggers. >>> > >>> > Essentially I'm trying to run this /bin/sed command, which works fine on >>> > the >>> > command line: >>> > /bin/sed -i -r 's/"groups": [$/"groups": [\n "TEST_admin",/' >>> > /user/chef-repo/data_bags/users/vagrant.json >>> > >>> > For testing here’s the pertinent portion of vagrant.json that /bin/sed >>> > is >>> > working on the /bin/sed command should add a line between groups and >>> > lastentry: >>> > >>> > "groups": [ >>> > "lastentry" >>> > ], >>> > >>> > Here’s the line in my Vagrantfile that executes the command: >>> > >>> > #Before we do anything with this box: >>> > config.trigger.before :up do >>> > admimquote = '"TEST_admin"' >>> > groupquote = '"groups"' >>> > runthis = "/bin//bin/sed -i -r 's/" + groupquote + ": \[$/" + >>> > groupquote >>> > + ": \["+'\n' + " " + admimquote + ",/' >>> > /user/chef-repo/data_bags/users/vagrant.json" >>> > >>> > run runthis >>> > end >>> > >>> > >>> > The error I get is: >>> > >>> > >>> > INFO warden: Calling OUT action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x000000024d1ed8> >>> > ERROR vagrant: Vagrant experienced an error! Details: >>> > ERROR vagrant: #<VagrantPlugins::Triggers::Errors::CommandFailed: The >>> > command "/bin/sed -i -r 's/"groups": [$/"groups": [\n "TEST_admin",/' >>> > /user/chef-repo/data_bags/users/vagrant.json" returned a failed exit >>> > code. >>> > The >>> > error output is shown below: >>> > >>> > /bin/sed: -e expression #1, char 47: unterminated `s' command >>> >> >>> > ERROR vagrant: The command "/bin/sed -i -r 's/"groups": [$/"groups": [\n >>> > "TEST_admin",/' /user/chef-repo/data_bags/users/vagrant.json" returned a >>> > failed exit code. The >>> > error output is shown below: >>> > >>> > /bin/sed: -e expression #1, char 47: unterminated `s' command >>> > >>> > ERROR vagrant: >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/dsl.rb:101:in >>> > `process_result' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/dsl.rb:54:in >>> > `run' >>> > /user/vagrant/Vagrantfile:38:in `block (2 levels) in <top (required)>' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:55:in >>> > `instance_eval' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:55:in >>> > `block in fire_triggers' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:51:in >>> > `each' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:51:in >>> > `fire_triggers' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:16:in >>> > `call' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in >>> > `call' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:17:in >>> > `call' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in >>> > `call' >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:17:in >>> > `call' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in >>> > `call' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builder.rb:116:in >>> > `call' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in >>> > `block in run' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/busy.rb:19:in >>> > `busy' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in >>> > `run' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:214:in >>> > `action_raw' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:191:in >>> > `block in action' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/environment.rb:516:in >>> > `lock' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:178:in >>> > `call' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:178:in >>> > `action' >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/batch_action.rb:82:in >>> > `block (2 levels) in run' >>> > INFO interface: error: The command "/bin/sed -i -r 's/"groups": >>> > [$/"groups": [\n "TEST_admin",/' >>> > /user/chef-repo/data_bags/users/vagrant.json" returned a failed exit >>> > code. >>> > The >>> > error output is shown below: >>> > >>> > /bin/sed: -e expression #1, char 47: unterminated `s' command >>> > >>> > The command "/bin/sed -i -r 's/"groups": [$/"groups": [\n >>> > "TEST_admin",/' >>> > /user/chef-repo/data_bags/users/vagrant.json" returned a failed exit >>> > code. >>> > The >>> > error output is shown below: >>> > >>> > /bin/sed: -e expression #1, char 47: unterminated `s' command >>> > >>> > INFO interface: Machine: error-exit >>> > ["VagrantPlugins::Triggers::Errors::CommandFailed", "The command >>> > \"/bin/sed >>> > -i -r 's/\"groups\": [$/\"groups\": [\\n \"TEST_admin\",/' >>> > /user/chef-repo/data_bags/users/vagrant.json\" returned a failed exit >>> > code. >>> > The\nerror output is shown below:\n\n/bin/sed: -e expression #1, char >>> > 47: >>> > unterminated `s' command\n"] >>> > >>> > >>> > >>> > >>> > Another thing I tried was moving the command to a bash shell script >>> > (prebootstrap.sh). >>> > >>> > >>> > INFO interface: info: Running triggers before up... >>> > INFO interface: info: ==> default: Running triggers before up... >>> > ==> default: Running triggers before up... >>> > INFO interface: info: Executing command "prebootstrap.sh"... >>> > INFO interface: info: ==> default: Executing command >>> > "prebootstrap.sh"... >>> > ==> default: Executing command "prebootstrap.sh"... >>> > INFO subprocess: Starting process: ["prebootstrap.sh"] >>> > ERROR warden: Error occurred: No such file or directory - >>> > prebootstrap.sh >>> > INFO warden: Beginning recovery process... >>> > INFO warden: Recovery complete. >>> > INFO warden: Beginning recovery process... >>> > INFO warden: Recovery complete. >>> > INFO warden: Beginning recovery process... >>> > INFO warden: Recovery complete. >>> > INFO environment: Relea/bin/sed process lock: >>> > machine-action-92cb79e7b5444cdf0349bca3ac36999e >>> > INFO environment: Running hook: environment_unload >>> > INFO runner: Preparing hooks for middleware sequence... >>> > INFO runner: 3 hooks defined. >>> > INFO runner: Running action: >>> > #<Vagrant::Action::Builder:0x00000002261ec8> >>> > INFO warden: Calling IN action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x00000002268db8> >>> > INFO warden: Calling IN action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x0000000228d078> >>> > INFO warden: Calling IN action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x000000022b5eb0> >>> > INFO warden: Calling OUT action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x000000022b5eb0> >>> > INFO warden: Calling OUT action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x0000000228d078> >>> > INFO warden: Calling OUT action: >>> > #<VagrantPlugins::Triggers::Action::Trigger:0x00000002268db8> >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/subprocess.rb:109:in >>> > `rescue in execute': No such file or directory - prebootstrap.sh >>> > (Vagrant::Util::Subprocess::LaunchError) >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/subprocess.rb:102:in >>> > `execute' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/subprocess.rb:22:in >>> > `execute' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/dsl.rb:44:in >>> > `block in run' >>> > from >>> > /opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler.rb:236:in >>> > `block >>> > in with_clean_env' >>> > from >>> > /opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler.rb:223:in >>> > `with_original_env' >>> > from >>> > /opt/vagrant/embedded/gems/gems/bundler-1.7.11/lib/bundler.rb:229:in >>> > `with_clean_env' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/dsl.rb:41:in >>> > `run' >>> > from /user/vagrant/Vagrantfile:33:in `block (2 levels) in <top >>> > (required)>' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:55:in >>> > `instance_eval' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:55:in >>> > `block in fire_triggers' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:51:in >>> > `each' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:51:in >>> > `fire_triggers' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:16:in >>> > `call' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in >>> > `call' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:17:in >>> > `call' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in >>> > `call' >>> > from >>> > >>> > /user/.vagrant.d/gems/gems/vagrant-triggers-0.5.0/lib/vagrant-triggers/action/trigger.rb:17:in >>> > `call' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/warden.rb:34:in >>> > `call' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/builder.rb:116:in >>> > `call' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in >>> > `block in run' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/util/busy.rb:19:in >>> > `busy' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/action/runner.rb:66:in >>> > `run' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:214:in >>> > `action_raw' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:191:in >>> > `block in action' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/environment.rb:516:in >>> > `lock' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:178:in >>> > `call' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/machine.rb:178:in >>> > `action' >>> > from >>> > >>> > /opt/vagrant/embedded/gems/gems/vagrant-1.7.2/lib/vagrant/batch_action.rb:82:in >>> > `block (2 levels) in run' >>> > >>> > So is this a vagrant-triggers issue or a >>> > /vagrant-1.7.2/lib/vagrant/util/subprocess.rb issue? or an environment >>> > variable issue? I don't think its the latter, as I've give the full path >>> > to >>> > /bin/sed and vagrant.json in the bash script. The error: No such file or >>> > directory is vague. If I run the prebootstrap.sh script it works fine. >>> > If I >>> > make a short test ruby scrip and exec('./prebootstrap.sh') it it works >>> > fine. >>> > >>> > Does anyone have any suggestions? >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> > Groups >>> > "Vagrant" group. >>> > To unsubscribe from this group and stop receiving emails from it, send >>> > an >>> > email to [email protected]. >>> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Vagrant" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Vagrant" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
