2017-10-20 224 views
0

我使用下面的資源從elasticsearch:紅寶石YAML陣列

elasticsearch_configure 'elasticsearch' do 
    configuration ({ 
     'path.repo' => ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"] 
    }) 
end 

我需要完全以下的輸出:

path.repo: ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"] 

但我得到以下之一:

path.repo: 
- "/backups/s3_currently_dev" 
- "/backups/s3_currently" 
- "/backups/s3_daily" 
- "/backups/s3_weekly" 
- "/backups/s3_monthly" 

這似乎並不奏效。我如何獲得所需的輸出?

重現:

1- Install Chef. 
2- Create a cookbook. 
3- Use elasticsearch community cookbook to install elasticsearch and configure with the resource shown. 
4- Use kitchen or vagrant to create. 
+0

你是說調用'path.repo'是給你一個YAML樣的結果?也許嘗試寫作重現步驟。 – henrebotha

+0

是的。如何將YAML結果更改爲我想要的輸出結果?我編輯了重現步驟。 – Lechucico

+0

如果你做了'path.repo.class',你會得到什麼? – henrebotha

回答

0

您可以分析使用YAML.load像這樣現有的輸出:

require 'yaml' 
=> true 

config = 'path.repo: 
- "/backups/s3_currently_dev" 
- "/backups/s3_currently" 
- "/backups/s3_daily" 
- "/backups/s3_weekly" 
- "/backups/s3_monthly"' 
=> "path.repo:\n- \"/backups/s3_currently_dev\"\n- \"/backups/s3_currently\"\n- \"/backups/s3_daily\"\n- \"/backups/s3_weekly\"\n- \"/backups/s3_monthly\"" 

doc = YAML.load config 
=> {"path.repo"=>["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]} 

doc["path.repo"] 
=> ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]