Class: Subspace::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/subspace/configuration.rb

Defined Under Namespace

Classes: GroupConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



6
7
8
9
10
# File 'lib/subspace/configuration.rb', line 6

def initialize
  @host_config = {}
  @group_config = {}
  @vars = OpenStruct.new
end

Instance Attribute Details

#host_configObject (readonly)

Returns the value of attribute host_config.



4
5
6
# File 'lib/subspace/configuration.rb', line 4

def host_config
  @host_config
end

#project_nameObject

Returns the value of attribute project_name.



3
4
5
# File 'lib/subspace/configuration.rb', line 3

def project_name
  @project_name
end

#varsObject (readonly)

Returns the value of attribute vars.



4
5
6
# File 'lib/subspace/configuration.rb', line 4

def vars
  @vars
end

Instance Method Details

#binding_for(host: nil, group: nil) ⇒ Object

I think a better way to do this is possibly to just write out all the host vars directly to a yaml file That provides more flexibility, although this method provides a whitelist.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/subspace/configuration.rb', line 43

def binding_for(host: nil, group: nil)
  config = @vars.dup
  if host
    @host_config[host].each do |k,v|
      config[k] = v
    end
  end
  b = binding
  b.local_variable_set(:config, config)
  b
end

#group(name, hosts: [], vars: {}) ⇒ Object



24
25
26
27
# File 'lib/subspace/configuration.rb', line 24

def group(name, hosts: [], vars: {})
  group_config(name).hosts += hosts
  group_config(name).vars.merge!(vars)
end

#groupsObject



20
21
22
# File 'lib/subspace/configuration.rb', line 20

def groups
  @group_config.keys
end

#host(name, options) ⇒ Object



12
13
14
# File 'lib/subspace/configuration.rb', line 12

def host(name, options)
  @host_config[name] = options
end

#hostsObject



16
17
18
# File 'lib/subspace/configuration.rb', line 16

def hosts
  @host_config.keys
end

#role(name, groups: [], vars: {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/subspace/configuration.rb', line 29

def role(name, groups: [], vars: {})
  groups.each do |group|
    group_config(group).roles.push(name.to_sym)
    vars.each do |k,v|
      if group_config(group).vars[k]
        put "Warning, variable '#{k}' already set for group '#{group}'"
      end
      group_config(group).vars[k] = v
    end
  end
end