在systemd下运行的Chef vs vs Chef-不同的宝石库 [英] chef-run vs chef under systemd - different gem repos

查看:84
本文介绍了在systemd下运行的Chef vs vs Chef-不同的宝石库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让厨师与我自己的本地餐厅交换官方的rubygems存储库。确实可以,但是说并非总是如此。

I'm trying to make chef swap the official rubygems repo with my own local one. It kind of does work but let's say 'not always'. More on that below.

bash-4.2$ /opt/chef/embedded/bin/gem sources
*** CURRENT SOURCES ***

https://rubygems.org/

厨师在systemd的控制下运行。当我检查日志时,到目前为止,厨师做了什么

Chef is running under control of systemd. When I check in journal what chef has done so far I get

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的代码如下

The code of my recipe mycookbook::gem is as follows

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)

如果我会再次检查宝石来源列表

If I check the list of gem sources again I'll get

bash-4.2$ /opt/chef/embedded/bin/gem sources
*** CURRENT SOURCES ***

https://rubygems.org/

不幸的是,到目前为止没有任何变化。现在,如果我直接从控制台运行Chef-client,那么我最终会看到Chef正在完成我想做的事情。

Unfortunately nothing has changed so far. Now, if I run chef-client directly from the console I finally see chef doing what I wanted to be done.

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/

当我打开调试模式时,我发现厨师声称不满足条件

When I turned on debug mode I noticed chef claiming the condition was not met

DEBUG: Skipping execute[del_official_https_rubygems_repo] due to only_if command `gem sources --list | /usr/bin/grep https://rubygems.org`

是什么?我做了进一步的调查,无奈之下添加到了食谱中。

Wth? I did some further investigation and in desperation added to the recipe

  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的内容让我非常困惑

Now when I checked the content of /tmp/chef_gem_sources I was utterly bewildered

cat chef_gem_sources 
*** CURRENT SOURCES ***

http://myrepo

最后,在/ tmp / chef_env,我找到了HOME = /。当我自己启动Chef-client时,显然是HOME = / root。由于.gemrc具有两个位置,并且在:sources部分中可能具有不同的值,因此具有很大的区别。

Finally, in /tmp/chef_env I found HOME=/. It's obviously HOME=/root when I launch chef-client myself. It makes a huge difference as .gemrc has two locations and may have different values in :sources section.

推荐答案

两个问题。首先,您想在两个执行资源上放置 action:nothing ,这样它们就不会在编译和收敛时发生。其次,输出有所不同,因为Chef在确定输出样式时会检查stdout是否为TTY。如果是TTY,则将获得新的格式化程序输出,否则将获得记录器输出。

Two issues. First you want to put action :nothing on your two execute resources so they don't happen at both compile and converge time. Second, the output differs because Chef checks if stdout is a TTY when determining the output style. If it is a TTY, you get the new formatter output, otherwise you get logger output.

这篇关于在systemd下运行的Chef vs vs Chef-不同的宝石库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆