Coder Social home page Coder Social logo

vagrant-host-shell's Introduction

vagrant-host-shell plugin

a vagrant provisioner to run commands on the host when a VM boots.

simple example based on question asked on vagrant mailing list

example usage

Install as a plugin:

vagrant plugin install vagrant-host-shell

Add this to Vagrantfile:

  config.vm.provision :host_shell do |host_shell|
    host_shell.inline = 'touch /tmp/hostshell-works && echo hello from the host && hostname 1>&2'
  end

Run vagrant up (or vagrant provision if machine is already running.)

Observe that /tmp/hostshell-works is present on your host, and that the provisioner output:

[stdout] hello from the host
[stderr] (your host's hostname)

vagrant-host-shell's People

Contributors

br0ken- avatar phinze avatar smerrill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vagrant-host-shell's Issues

Interactive?

Maybe bash -c -i or an interactive option?

Use case: user needs to check a couple of config files are correct, then hit Enter to continue (via read -p "Press Enter). Currently it just hangs

Does not work on Windows in Cygwin

This issue is continue of #3. Unfortunately, %PATH% variable is incorrect and does not contain all installed software.

My use case - is a provision Vagrant from a host machine.

config.vm.provision :host_shell, :inline => "ansible-playbook provisioning/provision.yml --limit=vagrant"

When I try do this:

[stderr] "C:/HashiCorp/Vagrant/embedded/bin/bash.EXE": /d/cygwin/bin/ansible-playbook: /usr/bin/python: bad interpreter: No such file or directory

Option to see output

Thanks for this plugin, Your spike is enough for what I am trying to do with one exception.
Is there a way to change the verbosity of the output of the command being run?
I am running a command that takes > 4 mins to finish and I'd like the users of my vagrantfile to know what is happening in the background.

command output redirection problem

config.vm.provision :host_shell do |host_shell|
host_shell.inline = 'vagrant ssh ucd_server -c "ec2metadata" > C:\tmp\ucd_server.txt'
end

the ec2metadata command works but the ucd_server.txt file is never created

Repeat shell execution after failure.

I want to know if the script execution failed (but I don't want provisioning to abort) so I can run it again in a loop. Is it possible to get access to the 'exitcode' variable somehow after exection completes?

I have set "abort_on_nonzero = false", but I'd like to run something like this in my Vagrantfile:

exitcode=1
while $exitcode != 0
    config.vm.provision :host_shell do |host_shell|
      host_shell.abort_on_nonzero = false
      host_shell.inline = "ansible-playbook apply-windows-updates.yml -e ansible_winrm_scheme=http -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory"
      exitcode = host_shell.exitcode
      config.vm.provision :reload
    end
end

Basically the Ansible way of applying Windows Updates will always fails during it's run if you try it often enough. All you need to do is reboot the box, and re-run the updates to try again. What I want to do is repeat this block until there are no errors reported... but I can't find a way to do this.

I can't do a reboot via Ansible as that wipes out any port forwarding that Vagrent sets up, hence the use of the "vagrant-reload" plugin to restart the VM the Vagrant way.

Does anyone have any ideas?

Fail on error

If any of the shell steps fail, it would be nice if the provisioning failed all together rather than just writing to stderr

vagrant ssh -c not returning

for some reason this never returns, it does if I run it on my host shell directly though

    config.vm.provision :host_shell, run: "always"  do|s| # evil hack to deal with stupid route problem
            s.inline = "vagrant ssh oracle -c 'setsid ping -q -i 5 172.28.128.3'"
    end

Triggering error around nokogiri and libxml incompatibility

My environment:
OS X Yosemite 10.10.3
Vagrant 1.7.2 (installed from the .dmg package)
vagrant-host-shell 0.0.4 installed using vagrant plugin install vagrant-host-shell
Using VirtualBox

Configuration:

config.vm.provision :host_shell do |host_shell|
  host_shell.inline = 'rspec specs/all_spec.rb'
end

Command and error message:

$ vagrant provision --provision-with=host_shell all
==> all: Running provisioner: host_shell...
[stderr] /opt/vagrant/embedded/gems/gems/nokogiri-1.6.3.1/lib/nokogiri.rb:29:in `require': dlopen(/opt/vagrant/embedded/gems/gems/nokogiri-1.6.3.1/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: @rpath/libxml2.dylib (LoadError)
  Referenced from: /opt/vagrant/embedded/gems/gems/nokogiri-1.6.3.1/lib/nokogiri/nokogiri.bundle
  Reason: Incompatible library version: nokogiri.bundle requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /opt/vagrant/embedded/gems/gems/nokogiri-1.6.3.1/lib/nokogiri/nokogiri.bundle
    from /opt/vagrant/embedded/gems/gems/nokogiri-1.6.3.1/lib/nokogiri.rb:29:in `rescue in <top (required)>'
    from /opt/vagrant/embedded/gems/gems/nokogiri-1.6.3.1/lib/nokogiri.rb:25:in `<top (required)>'
    from /Users/amos.shapira/.vagrant.d/gems/gems/capybara-2.4.4/lib/capybara.rb:2:in `require'
    from /Users/amos.shapira/.vagrant.d/gems/gems/capybara-2.4.4/lib/capybara.rb:2:in `<top (required)>'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster/contexts/capybara_context.rb:1:in `require'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster/contexts/capybara_context.rb:1:in `<top (required)>'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster/contexts.rb:5:in `require'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster/contexts.rb:5:in `<top (required)>'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster.rb:5:in `require'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster.rb:5:in `<top (required)>'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster/rspec.rb:1:in `require'
    from /Users/amos.shapira/.vagrant.d/gems/gems/infrataster-0.3.0/lib/infrataster/rspec.rb:1:in `<top (required)>'
    from /Users/amos.shapira/Documents/configuration/specs/spec_helper.rb:1:in `require'
    from /Users/amos.shapira/Documents/configuration/specs/spec_helper.rb:1:in `<top (required)>'
    from /Users/amos.shapira/Documents/configuration/specs/all_spec.rb:1:in `require'
    from /Users/amos.shapira/Documents/configuration/specs/all_spec.rb:1:in `<top (required)>'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1327:in `load'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1325:in `each'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:102:in `setup'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:88:in `run'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:73:in `run'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:41:in `invoke'
    from /Users/amos.shapira/.vagrant.d/gems/gems/rspec-core-3.3.1/exe/rspec:4:in `<top (required)>'
    from /usr/bin/rspec:23:in `load'
    from /usr/bin/rspec:23:in `<main>'

Other provisioners don't have an issue running.
The only Google search result for this error message is this Vagrant issue from a year ago: hashicorp/vagrant#3794
I'm not sure it's relevant (it relates more about plugin installation issues), and so far following the voodoo steps suggested there didn't help.

fail on error

==> distributed: Running provisioner: host_shell...
[stderr] cp: configuration/runtime/developer-runtime/slave-dex.conf: No such file or directory

this should have bailed out of the deploy not just print, it should act like vagrant shell

Fails to install on Fedora 33

$ vagrant plugin install vagrant-host-shell
Installing the 'vagrant-host-shell' plugin. This can take a few minutes...
Vagrant failed to properly resolve required dependencies. These
errors can commonly be caused by misconfigured plugin installations
or transient network issues. The reported error is:

conflicting dependencies racc (= 1.4.16) and racc (= 1.5.1)
  Activated racc-1.5.1
  which does not match conflicting dependency (= 1.4.16)

  Conflicting dependency chains:
    racc (= 1.5.1), 1.5.1 activated

  versus:
    racc (= 1.4.16)

  Gems matching racc (= 1.4.16):
    racc-1.4.16

$ cat /etc/os-release 
NAME=Fedora
VERSION="33 (Workstation Edition)"
ID=fedora
VERSION_ID=33
VERSION_CODENAME=""
PLATFORM_ID="platform:f33"
PRETTY_NAME="Fedora 33 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:33"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f33/system-administrators-guide/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=33
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=33
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Workstation Edition"
VARIANT_ID=workstation

$ vagrant --version
Vagrant 2.2.9

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

$ gem --version
3.1.4

Does not work on Windows.

When I try to run this on Windows, I get the following error:

The executable '/bin/bash' Vagrant is trying to run was not
found in the %PATH% variable. This is an error. Please verify
this software is installed and on the path.

host os options

in order to ensure sane deployment on multiple host os (like windows (and powershell vs dos)) you should document or add an option to specify that, so bash commands, or gnu (since OS X isn't all GNU) aren't attempted to be run on windows.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.