trigger.run inline ptarsing is behaving strangely

8 views
Skip to first unread message

Jamie Jackson

unread,
Aug 16, 2019, 5:45:53 PM8/16/19
to vagra...@googlegroups.com
I have this:

  config.trigger.after :destroy do |trigger|

    trigger.info = "Removing provisioned directory contents: #{host_provisioned_dir}/*"

    trigger.run = {inline: "rm \"#{host_provisioned_dir}/\"* || true"}

  end


vagrant destroy gives this:

==> default: Running action triggers after destroy ...
==> default: Running trigger...
==> default: Removing provisioned directory contents: /Users/jjackson/Sites/hud/hudx_git/vagrant_cfml/temp/provisioned/*
    default: Running local: Inline script
    default: rm "/Users/jjackson/Sites/hud/hudx_git/vagrant_cfml/temp/provisioned/"* || true
    default: rm: /Users/jjackson/Sites/hud/hudx_git/vagrant_cfml/temp/provisioned/*: No such file or directory
    default: rm: ||: No such file or directory
    default: rm: true: No such file or directory
==> default: Trigger run failed
==> default: A script exited with an unacceptable exit code 1.
A script exited with an unacceptable exit code 1.

It seems to be doing some strange and unexpected parsing of my command.

Am I doing something wrong? Is it related to this? https://github.com/hashicorp/vagrant/issues/10099

Thanks,
Jamie

Brian Cain

unread,
Aug 16, 2019, 5:58:07 PM8/16/19
to vagra...@googlegroups.com
On Fri, Aug 16, 2019 at 2:45 PM Jamie Jackson <jamie...@gmail.com> wrote:
I have this:

  config.trigger.after :destroy do |trigger|

    trigger.info = "Removing provisioned directory contents: #{host_provisioned_dir}/*"

    trigger.run = {inline: "rm \"#{host_provisioned_dir}/\"* || true"}

  end


vagrant destroy gives this:

==> default: Running action triggers after destroy ...
==> default: Running trigger...
==> default: Removing provisioned directory contents: /Users/jjackson/Sites/hud/hudx_git/vagrant_cfml/temp/provisioned/*
    default: Running local: Inline script
    default: rm "/Users/jjackson/Sites/hud/hudx_git/vagrant_cfml/temp/provisioned/"* || true
    default: rm: /Users/jjackson/Sites/hud/hudx_git/vagrant_cfml/temp/provisioned/*: No such file or directory
    default: rm: ||: No such file or directory
    default: rm: true: No such file or directory
==> default: Trigger run failed
==> default: A script exited with an unacceptable exit code 1.
A script exited with an unacceptable exit code 1.

It seems to be doing some strange and unexpected parsing of my command.

I know this isn't very intuitive :( I thought maybe there was an issue on GitHub to document this, but if you want to run bash, you need to wrap
your run call in bash. The run option isn't bash like a shell provisioner. So if you did something like:

trigger.run = {inline: "bash -c 'rm \"#{host_provisioned_dir}/\"* || true'"}
 
You'll get the desired effect I believe. I didn't test that, so you might have to mess with the nested quotes by the way. But the essential idea here
is it needs to be wrapped in `bash -c` if you want to run a bash like your example

Am I doing something wrong? Is it related to this? https://github.com/hashicorp/vagrant/issues/10099

Thanks,
Jamie

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPc2zYm%3D1A4HGi%3DgBr8yqh%2BFVEhZRe9TJGLNH2Q1XKcqEg%40mail.gmail.com.


--
Brian Cain

Jamie Jackson

unread,
Aug 19, 2019, 4:52:14 PM8/19/19
to vagra...@googlegroups.com
Okay, thanks for the explanation, Brian.

Reply all
Reply to author
Forward
0 new messages