Help us understand the problem. What is going on with this article?

[ chef ]data_bagsの書き方と取り出し方その2(配列パターン)

More than 5 years have passed since last update.

1. data_bags

data_bags/sample/sample002.json
{
    "id":"sample002",
    "samplekey02":[
        "value001",
        "value002",
        "value003",
        "value004",
        "value005"
    ],

    (...中略)

}

key(i.e."samplekey02")にひもづく配列を格納する。この場合は[]で配列の要素を囲む。

2. recipe

recipe/sample.rb
array_item = data_bag_item('sample','sample002')['samplekey02']
tmp_array << array_item

例えばこのように配列ごとdata_bagsから取り出して、別の配列tmp_arrayに追加することができる。
またはeach文で繰り返し処理などでも使える。

penguin_dream
フロントエンド(主にjavascript)、プログラミング、インフラ構築、インフラ運用、CIなどのメモ。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away