Class: Chef::Resource::ChefRole

Inherits:
LWRPBase
  • Object
show all
Defined in:
lib/chef/resource/chef_role.rb

Constant Summary collapse

NOT_PASSED =

‘NOT_PASSED` is defined in chef-12.5.0, this guard will ensure we don’t redefine it if it’s already there

Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ChefRole

Grab environment from with_environment



14
15
16
17
# File 'lib/chef/resource/chef_role.rb', line 14

def initialize(*args)
  super
  chef_server run_context.cheffish.current_chef_server
end

Instance Attribute Details

#default_attribute_modifiersObject (readonly)

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



43
44
45
# File 'lib/chef/resource/chef_role.rb', line 43

def default_attribute_modifiers
  @default_attribute_modifiers
end

#override_attribute_modifiersObject (readonly)

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



61
62
63
# File 'lib/chef/resource/chef_role.rb', line 61

def override_attribute_modifiers
  @override_attribute_modifiers
end

#run_list_modifiersObject (readonly)

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 ”



78
79
80
# File 'lib/chef/resource/chef_role.rb', line 78

def run_list_modifiers
  @run_list_modifiers
end

#run_list_removersObject (readonly)

Returns the value of attribute run_list_removers.



79
80
81
# File 'lib/chef/resource/chef_role.rb', line 79

def run_list_removers
  @run_list_removers
end

Instance Method Details

#default_attribute(attribute_path, value = NOT_PASSED, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/resource/chef_role.rb', line 44

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

#override_attribute(attribute_path, value = NOT_PASSED, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/chef/resource/chef_role.rb', line 62

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) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/chef/resource/chef_role.rb', line 80

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) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/chef/resource/chef_role.rb', line 94

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) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/chef/resource/chef_role.rb', line 101

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

#role(*roles) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/chef/resource/chef_role.rb', line 87

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