Class: Hyrb::Models::AnsibleHost

Inherits:
Hyrb::Model show all
Defined in:
lib/hyrb/models/ansible_host.rb

Instance Attribute Summary collapse

Attributes inherited from Hyrb::Model

#data, #path

Instance Method Summary collapse

Methods inherited from Hyrb::Model

#filepath, #load_config_file, #reload!, #save!

Constructor Details

#initialize(project, environment) ⇒ AnsibleHost

Returns a new instance of AnsibleHost.



6
7
8
9
10
11
12
13
# File 'lib/hyrb/models/ansible_host.rb', line 6

def initialize(project, environment)
  @path = File.join(project.ansible_path, "hosts")
  @data = deserialize(load_config_file) || []
  self.host = environment.label
  self.ansible_ssh_host = environment.host
  # TODO: this should be different on eg EC2
  self.ansible_ssh_user = "root"
end

Instance Attribute Details

#ansible_ssh_hostObject

Returns the value of attribute ansible_ssh_host.



4
5
6
# File 'lib/hyrb/models/ansible_host.rb', line 4

def ansible_ssh_host
  @ansible_ssh_host
end

#ansible_ssh_userObject

Returns the value of attribute ansible_ssh_user.



4
5
6
# File 'lib/hyrb/models/ansible_host.rb', line 4

def ansible_ssh_user
  @ansible_ssh_user
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/hyrb/models/ansible_host.rb', line 4

def host
  @host
end

Instance Method Details

#serialize(data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hyrb/models/ansible_host.rb', line 15

def serialize(data)
  # remove the host that we're working on
  data.reject! { |h| h["host"] == host }
  data += [{
    host: host,
    vars: {
      ansible_ssh_host: ansible_ssh_host,
      ansible_ssh_user: ansible_ssh_user,
    }.stringify_keys,
  }.stringify_keys]
end