我试图让厨师用我自己的当地人交换官方rubygems回购。它确实有用,但让我们说“并不总是”。更多关于以下内容。
bash-4.2$ /opt/chef/embedded/bin/gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
Chef在systemd的控制下运行。当我在日记中查看到目前为止厨师做了什么
Jan 14 07:39:24 myserver.srv chef-client[32274]: [2016-01-14T07:39:24+01:00] INFO: Processing execute[add_my_own_repo] action run (mycookbook::gem line 5)
Jan 14 07:39:24 myserver.srv chef-client[32274]: [2016-01-14T07:39:24+01:00] INFO: Processing execute[Guard resource] action run (dynamically defined)
Jan 14 07:39:24 myserver.srv chef-client[32274]: [2016-01-14T07:39:24+01:00] INFO: execute[Guard resource] ran successfully
Jan 14 07:39:24 myserver.srv chef-client[32274]: [2016-01-14T07:39:24+01:00] INFO: Processing execute[del_official_https_rubygems_repo] action run (mycookbook::gem line 10)
Jan 14 07:39:24 myserver.srv chef-client[32274]: [2016-01-14T07:39:24+01:00] INFO: Processing execute[Guard resource] action run (dynamically defined)
我的食谱mycookbook :: gem的代码如下
execute 'add_my_own_repo' do
command '/opt/chef/embedded/bin/gem sources --add http://myrepo'
not_if '/opt/chef/embedded/bin/gem sources --list | grep myrepo'
end.run_action(:run)
execute 'del_official_https_rubygems_repo' do
command '/opt/chef/embedded/bin/gem sources --remove https://rubygems.org/'
only_if '/opt/chef/embedded/bin/gem sources --list | grep https://rubygems.org'
end.run_action(:run)
如果我再次检查宝石资源清单,我会得到
bash-4.2$ /opt/chef/embedded/bin/gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
遗憾的是到目前为止没有任何改变。现在,如果我直接从控制台运行chef-client,我终于看到厨师正在做我想做的事情。
Recipe: mycookbook::gem
* execute[add_my_own_repo] action run
- execute /opt/chef/embedded/bin/gem sources --add http://myrepo
* execute[del_official_https_rubygems_repo] action run
- execute /opt/chef/embedded/bin/gem sources --remove https://rubygems.org/
当我打开调试模式时,我注意到厨师声称不符合条件
DEBUG: Skipping execute[del_official_https_rubygems_repo] due to only_if command `gem sources --list | /usr/bin/grep https://rubygems.org`
WTH?我做了一些进一步的调查,并在绝望中加入了食谱
execute 'CHEF_ENV' do
command 'env >> /tmp/chef_env'
end.run_action(:run)
execute 'GEM_SOURCES' do
command 'gem sources --list >> /tmp/chef_gem_sources'
end.run_action(:run)
现在当我检查/ tmp / chef_gem_sources的内容时,我感到非常困惑
cat chef_gem_sources
*** CURRENT SOURCES ***
http://myrepo
最后,在/ tmp / chef_env中我找到了HOME = /。当我自己推出厨师 - 客户时,它显然是HOME = / root。它有很大的不同,因为.gemrc有两个位置,可能在:sources section。
中有不同的值答案 0 :(得分:1)
两个问题。首先,您希望将action :nothing
放在两个执行资源上,这样它们就不会在编译和收敛时发生。其次,输出不同,因为Chef在确定输出样式时检查stdout是否为TTY。如果它是TTY,则获得新的格式化程序输出,否则您将获得记录器输出。