簡體   English   中英

主廚shell_out僅給出十六進制值

[英]Chef shell_out just giving hex values

我在下面創建廚師食譜。 但是,我的shell_out調用只是返回擴展變量的十六進制值。 如何在變量中獲取find命令的值,而不是垃圾十六進制值?

這是我的食譜中的相關代碼片段:

so = nil

bash "getPath" do
  Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
  command = "find \/ -path \\*ohai\/plugins"
  so = shell_out(command)
end

listOfFiles = ["#{so}\cert.rb","#{so}\key.rb","#{so}\perms.rb","#{so}\propertiesFiles.rb","#{so}\warFiles.rb","#{so}\yum.rb"]
templates = { 1 => "cert.rb", 2 => "key.rb", 3 => "perms.rb", 4 => "propertiesFiles.rb", 5 => "warFiles.rb", 6 => "yum.rb" }
i = 1

listOfFiles.each do |remote|
  template "#{remote}" do
    source 'cert.rb' #this is going to be a variable once I figure out how to call it from the "templates" hash. Just doing a static file for troubleshooting purposes now
    owner 'root'
    group 'root'
    mode '0644'
  action :create
  end
end

這是Chef-client運行輸出的一部分:

- create new file #<Mixlib::ShellOut:0x00000004dd88b8>yum.rb
- update content in file #<Mixlib::ShellOut:0x00000004dd88b8>yum.rb from none to fccd51
--- #<Mixlib::ShellOut:0x00000004dd88b8>yum.rb      2016-10-31 11:52:40.652276263 -0400
+++ ./.chef-#<Mixlib::ShellOut:0x00000004dd88b8>yum20161031-8408-1svdruo.rb 2016-10-31 11:52:40.652276263 -0400
@@ -1 +1,17 @@
+#
+# Cookbook Name:: inventory
+# Recipe:: default
+#
+# Copyright (c) 2016 me, All Rights Reserved.
+
+Ohai.plugin(:Cert) do
+  provides 'certFiles'
+
+  collect_data(:linux) do
+    certFiles Mash.new
+    so = shell_out("find \/ -name \"*.crt\"")
+    certFiles[:values] = so.stdout
+  end
+end
+
- change mode from '' to '0644'
- change owner from '' to 'root'
- change group from '' to 'root'
- restore selinux security context
  * ohai[reload] action reloadPuTTYPuTTYPuTTYPuTTYPuTTY
- re-run ohai and merge results into node attributes

Running handlers:
Running handlers complete
Chef Client finished, 8/20 resources updated in 05 seconds
[root@host plugins]# PuTTYPuTTYPuTTYPuTTYPuTTY^C

快好了!

so = shell_out(command) # Returns a Mixlib::ShellOut object
output = so.stdout      # Returns stdout of your command, as String

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM