使用 Chef 从工作站在远程服务器上安装软件

install software on remote server from the workstation using chef

厨师新手。

设法使用 this 示例创建 google 云虚拟机实例,甚至删除它们。

(1..2).each do |i|
  # <name of cookbook>_instance will lead to instance.rb . weird.
  google_cloud_instance "#{name_prefix}-#{i}" do
    machine_type 'n1-standard-1'
    zone_name "#{zone_a}"
    boot_disk_image "debian-7-wheezy-v20140408"
    service_account_scopes ["compute", "userinfo.email", "devstorage.full_control"]
    tags ["application-server"]    # TODO take from metadata
    metadata "application-server"=> true, "foo"=>"bar"
    auto_restart true
    on_host_maintenance "TERMINATE"
    # enable turbo mode!
    wait_for false
    # bootstrap attributes
    first_boot_json FIRST_BOOT
    client_rb CLIENT_RB
    validation_pem VALIDATION_PEM
    # auth
    client_email AUTH_EMAIL
    project_id AUTH_PROJECT
    key_location AUTH_KEYPATH
    action :create
  end
  servers << "#{name_prefix}-#{i}"
end

运行 此代码在 chef-workstation 使用

chef-client -z -o 'google_cloud::gce-create-service-server'

现在,我想在我创建的机器上安装软件。 例如 ruby 2.1rabbitmq 等。 我必须使用厨师服务器吗?如果没有,怎么办?如果可以,我可以只使用命令行来完成吗?

这不是开始学习 Chef 的好地方。您的问题的答案是在第一次启动 JSON 中设置一个 run_list 密钥,其中的配方 运行 对应于您希望服务器执行的操作。

更一般地说,您应该查看 https://learn.chef.io/ 以开始学习烹饪书和食谱等 Chef 基础知识。