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

not_if / only_if don't work inside a define #161

Closed
smlx opened this issue Sep 6, 2015 · 2 comments
Closed

not_if / only_if don't work inside a define #161

smlx opened this issue Sep 6, 2015 · 2 comments

Comments

@smlx
Copy link

smlx commented Sep 6, 2015

If the not_if/only_if directives could be applied to all resources
contained within a define, it would help to DRY up my code.. right now I'm
using a workaround like this:

define :bootstrap_install do
  test_cmd = "dpkg-query -Wf'${db:Status-abbrev}' #{params[:name]} | grep '^i'"
  installed = run_command(test_cmd, error: false).exit_status == 0

  # run install if required
  (params[:name], params[:dependencies]).map do |pkg|
    "/tmp/#{pkg}_amd64.deb"
  end.each do |path|
    remote_file path do
      not_if installed
    end
    execute "dpkg -i #{path}" do
      not_if installed
    end
    file path do
      action :delete
      not_if installed
    end
  end
end

Whereas I'd like to be able to do:

define :bootstrap_install do
  not_if "dpkg-query -Wf'${db:Status-abbrev}' #{params[:name]} | grep '^i'"

  (params[:name], params[:dependencies]).map do |pkg|
    "/tmp/#{pkg}_amd64.deb"
  end.each do |path|
    remote_file path
    execute "dpkg -i #{path}"
    file path do
      action :delete
    end
  end
end
@ryotarai
Copy link
Member

ryotarai commented Sep 7, 2015

Thank you for your report.
This is a known problem and not fixed yet. I'll try to fix this.

I think the following workaround is better:

define :bootstrap_install do
  test_cmd = "dpkg-query -Wf'${db:Status-abbrev}' #{params[:name]} | grep '^i'"
  installed = run_command(test_cmd, error: false).exit_status == 0

  unless installed
    # run install if required
    (params[:name], params[:dependencies]).map do |pkg|
      "/tmp/#{pkg}_amd64.deb"
    end.each do |path|
      remote_file path
      execute "dpkg -i #{path}"
      file path do
        action :delete
      end
    end
  end
end

@sue445
Copy link
Member

sue445 commented Nov 12, 2018

Released at v1.10.0
c.f. #271

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

No branches or pull requests

3 participants