invoking knife in a ruby class

后端 未结 4 1054
迷失自我
迷失自我 2021-02-11 01:38

I\'d like to create a nice wrapper class around knife to allow a program to run knife commands in a readable manner. I\'m currently trying to use the knife.rb file in the chef

4条回答
  •  -上瘾入骨i
    2021-02-11 02:05

    You could refer to following solution: http://lists.opscode.com/sympa/arc/chef/2011-08/msg00014.html

        require 'rubygems'
        require "chef"
        require "chef/knife/core/bootstrap_context"
        require 'chef/knife'
        require 'chef/knife/ssh'
        require 'net/ssh'
        require 'net/ssh/multi'
        require 'chef/knife/bootstrap'
    
        Chef::Config.from_file(File.expand_path('~/.chef/knife.rb'))
        kb = Chef::Knife::Bootstrap.new
        kb.name_args = "some.host"
        kb.config[:ssh_user] = "ubuntu"
        kb.config[:run_list] = "role[test]"
        kb.config[:use_sudo] = true
        kb.run
    

提交回复
热议问题