Frage

I'm trying to change the gem source using execute resource but I need to do this just one time.

remove_rubygems = 'gem sources -r http://rubygems.org/'

execute 'change sources to our gem server' do
  command "#{remove_rubygems} && gem sources -a http://mygemserver"
  creates "~/.gemrc"
end

All this because when I execute this resource many times the .gemrc file look like it.

vagrant@leibniz-app:~$ gem source
*** CURRENT SOURCES ***

http://mygemserver/
http://mygemserver/
http://mygemserver/
http://mygemserver/
...

Then, I want mygemserver one time in the .gemrc file.

How can I do it?

Is there any way to know the content of .gemrc before the execute my resource.?

War es hilfreich?

Lösung

Don't use ~/ in your path; this is why the creates line was not working to prevent the execute resource from being run when the file already existed.

execute 'change sources to our gem server' do
  command "#{remove_rubygems} && gem sources -a http://mygemserver"
  creates "/root/.gemrc"
end

Alternately, if you want to check whether the file contains a specific line:

execute 'change sources to our gem server' do
  command "#{remove_rubygems} && gem sources -a http://mygemserver"
  not_if "grep -F -q -e http://mygemserver/ ~/.gemrc" # this uses a shell, so the
                                                      # tilde should work here.
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top