Class: BuckKnife::ProjectAssign

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

Instance Method Summary collapse

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chef/knife/project_assign.rb', line 12

def run
  project   = project_from_arg_or_ask
  node_name = @name_args[1]
  nodes     = Array(project.node(node_name) || project.nodes)

  nodes.each do |node|
    ui.output "# Run this command to assign project attributes to #{node.name}:"

    code_block = "node = nodes.search(:name => \"\#{node.name}\").first\nnode.set[:\#{BuckKnife.namespace}][:project] = \"\#{project.name}\"\nnode.set[:\#{BuckKnife.namespace}][:environment] = \"\#{node.environment}\"\nnode.save\n    EOF\n\n    ui.output BuckKnife::Command.new(\"knife\").arg(\"exec\").opt(\"-E\", code_block )\n  end\nend\n".gsub("\n", "; ")