1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

knife searchで複数のキーワードを指定する

Last updated at Posted at 2013-03-14

こんな感じ。
括弧も使える。
書いてないけどワイルドカード(*)も使えます。

tagにWebかつproductionを割り当てたNode一覧をサーチ
$ knife search node "tags:web AND tags:production"
recipe[hoge]がrun_listにあり,tagがproduction又はdevelopmentのNode
$ knife search node "recipe:hoge AND (tags:production  OR tags:development)"

ではrecipe内で似たようなことをする時はというと、
これでもよいですが

default.rb
if(node[:roles].include?("web-server") &&
   node[:tags].include?("wordpress-web-servers"))

searchを使うのも良いかもですね。
以前書いたwordpress構築recipeから抜粋。

search例
#
# recipe実行ノードがMySQLDBサーバ(Master)であれば初期化実行
#
if(node[:roles].include?("db-server") && node[:tags].include?("wordpress-db-master"))
  # アクセス許可するWebサーバを検索し、サーバの内部IPからアクセスできるよう権限付与
  web_server = search(:node,"role:web-server AND tags:wordpress-web-servers")
  web_server.each do |sv|
    execute "access-accept" do
      command %Q{mysql -u root -e "grant all privileges on *.* to '%'@#{sv["cloud"]["local_ipv4"]}"}
    end
  end

  execute "flush-privileges" do
    command %Q{mysql -u root -e "flush privileges"}
  end
  directory "/tmp/dbdata" do
    action :create
  end

  directory "/tmp/dbdata" do
    action :create
  end

  git "/tmp/dbdata" do
        repository app["repo"]
        reference "master"
        action :sync
  end

  execute "createdb" do
        command "mysql -u root -h localhost < /tmp/dbdata/initWordpress.sql"
        action :run
  end
end
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?