diff --git a/crowbar_framework/app/models/node.rb b/crowbar_framework/app/models/node.rb index d63959f7c7..aeb35f4605 100644 --- a/crowbar_framework/app/models/node.rb +++ b/crowbar_framework/app/models/node.rb @@ -39,6 +39,7 @@ def initialize(node, role = nil) raise Crowbar::Error::NotFound.new end end + Node.ensure_node_role(node, @role.name) # deep clone of @role.default_attributes, used when saving node @attrs_last_saved = @role.default_attributes.deep_dup @node = node @@ -1701,13 +1702,20 @@ def create_new_role(new_name, machine) role.default_attributes["crowbar"]["network"] = {} role.save - # This run_list call is to add the crowbar tracking role to the node. (SAFE) - machine.run_list.run_list_items << "role[#{role.name}]" - machine.save + Node.ensure_node_role(machine, role.name) role end + def ensure_node_role(node, role_name = nil) + role_name = make_role_name(node.name) if role_name.nil? + return if node.run_list.include?("role[#{role_name}]") + + # This run_list call is to add the crowbar tracking role to the node. (SAFE) + node.run_list << "role[#{role_name}]" + node.save + end + def create_new(new_name) machine = Chef::Node.new machine.name "#{new_name}"