Class: Chef::Knife::RoleRunListReplace

Inherits:
Knife
  • Object
show all
Defined in:
lib/chef/knife/role_run_list_replace.rb

Instance Method Summary collapse

Instance Method Details

#replace_in_env_run_list(role, environment, old_entry, new_entry) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chef/knife/role_run_list_replace.rb', line 33

def replace_in_env_run_list(role, environment, old_entry, new_entry)
  nlist = []
  role.run_list_for(environment).each do |entry|
    if entry == old_entry
      nlist << new_entry
    else
      nlist << entry
    end
  end
  role.env_run_lists_add(environment => nlist)
end

#runObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chef/knife/role_run_list_replace.rb', line 45

def run
  role = Chef::Role.load(@name_args[0])
  role.name(@name_args[0])
  environment = "_default"
  old_entry = @name_args[1]
  new_entry = @name_args[2]

  replace_in_env_run_list(role, environment, old_entry, new_entry)
  role.save
  config[:env_run_list] = true
  output(format_for_display(role))
end