class Chef::Resource::ChefRole

Attributes

default_attribute_modifiers[R]

default_attribute 'ip_address', '127.0.0.1' default_attribute [ 'pushy', 'port' ], '9000' default_attribute 'ip_addresses' do |existing_value|

(existing_value || []) + [ '127.0.0.1' ]

end default_attribute 'ip_address', :delete

override_attribute_modifiers[R]

override_attribute 'ip_address', '127.0.0.1' override_attribute [ 'pushy', 'port' ], '9000' override_attribute 'ip_addresses' do |existing_value|

(existing_value || []) + [ '127.0.0.1' ]

end override_attribute 'ip_address', :delete

run_list_modifiers[R]

Order matters–if two things here are in the wrong order, they will be flipped in the run list recipe 'apache', 'mysql' recipe 'recipe@version' recipe 'recipe' role ''

run_list_removers[R]

Public Instance Methods

augment_new_json(json) click to toggle source
# File lib/chef/resource/chef_role.rb, line 134
def augment_new_json(json)
  # Apply modifiers
  json["run_list"] = apply_run_list_modifiers(new_resource.run_list_modifiers, new_resource.run_list_removers, json["run_list"])
  json["default_attributes"] = apply_modifiers(new_resource.default_attribute_modifiers, json["default_attributes"])
  json["override_attributes"] = apply_modifiers(new_resource.override_attribute_modifiers, json["override_attributes"])
  json
end
data_handler() click to toggle source
# File lib/chef/resource/chef_role.rb, line 150
def data_handler
  Chef::ChefFS::DataHandler::RoleDataHandler.new
end
default_attribute(attribute_path, value = NOT_PASSED, &block) click to toggle source
# File lib/chef/resource/chef_role.rb, line 25
def default_attribute(attribute_path, value = NOT_PASSED, &block)
  @default_attribute_modifiers ||= []
  if value != NOT_PASSED
    @default_attribute_modifiers << [ attribute_path, value ]
  elsif block
    @default_attribute_modifiers << [ attribute_path, block ]
  else
    raise "default_attribute requires either a value or a block"
  end
end
keys() click to toggle source
# File lib/chef/resource/chef_role.rb, line 154
def keys
  {
    "name" => :role_name,
    "description" => :description,
    "run_list" => :run_list,
    "env_run_lists" => :env_run_lists,
    "default_attributes" => :default_attributes,
    "override_attributes" => :override_attributes,
  }
end
load_current_resource() click to toggle source
# File lib/chef/resource/chef_role.rb, line 124
def load_current_resource
  @current_resource = json_to_resource(rest.get("roles/#{new_resource.role_name}"))
rescue Net::HTTPClientException => e
  if e.response.code == "404"
    @current_resource = not_found_resource
  else
    raise
  end
end
override_attribute(attribute_path, value = NOT_PASSED, &block) click to toggle source
# File lib/chef/resource/chef_role.rb, line 43
def override_attribute(attribute_path, value = NOT_PASSED, &block)
  @override_attribute_modifiers ||= []
  if value != NOT_PASSED
    @override_attribute_modifiers << [ attribute_path, value ]
  elsif block
    @override_attribute_modifiers << [ attribute_path, block ]
  else
    raise "override_attribute requires either a value or a block"
  end
end
recipe(*recipes) click to toggle source
# File lib/chef/resource/chef_role.rb, line 61
def recipe(*recipes)
  if recipes.size == 0
    raise ArgumentError, "At least one recipe must be specified"
  end

  @run_list_modifiers ||= []
  @run_list_modifiers += recipes.map { |recipe| Chef::RunList::RunListItem.new("recipe[#{recipe}]") }
end
remove_recipe(*recipes) click to toggle source
# File lib/chef/resource/chef_role.rb, line 79
def remove_recipe(*recipes)
  if recipes.size == 0
    raise ArgumentError, "At least one recipe must be specified"
  end

  @run_list_removers ||= []
  @run_list_removers += recipes.map { |recipe| Chef::RunList::RunListItem.new("recipe[#{recipe}]") }
end
remove_role(*roles) click to toggle source
# File lib/chef/resource/chef_role.rb, line 88
def remove_role(*roles)
  if roles.size == 0
    raise ArgumentError, "At least one role must be specified"
  end

  @run_list_removers ||= []
  @run_list_removers += roles.map { |recipe| Chef::RunList::RunListItem.new("role[#{role}]") }
end
resource_class() click to toggle source

Helpers

# File lib/chef/resource/chef_role.rb, line 146
def resource_class
  Chef::Resource::ChefRole
end
role(*roles) click to toggle source
# File lib/chef/resource/chef_role.rb, line 70
def role(*roles)
  if roles.size == 0
    raise ArgumentError, "At least one role must be specified"
  end

  @run_list_modifiers ||= []
  @run_list_modifiers += roles.map { |role| Chef::RunList::RunListItem.new("role[#{role}]") }
end