Class: Anvil::Cloudinit::Generator

Inherits:
Struct
  • Object
show all
Defined in:
lib/anvil/cloudinit/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



5
6
7
# File 'lib/anvil/cloudinit/generator.rb', line 5

def filename
  @filename
end

#hostnameObject

Returns the value of attribute hostname

Returns:

  • (Object)

    the current value of hostname



5
6
7
# File 'lib/anvil/cloudinit/generator.rb', line 5

def hostname
  @hostname
end

#public_key_pathObject

Returns the value of attribute public_key_path

Returns:

  • (Object)

    the current value of public_key_path



5
6
7
# File 'lib/anvil/cloudinit/generator.rb', line 5

def public_key_path
  @public_key_path
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



5
6
7
# File 'lib/anvil/cloudinit/generator.rb', line 5

def user
  @user
end

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
# File 'lib/anvil/cloudinit/generator.rb', line 6

def call
  public_key = public_key_path.to_s.gsub("~", Dir.home)

  if File.exist?(public_key)
    puts File.read(filename).gsub("%{USER}", user).gsub("%{HOSTNAME}", hostname).gsub("%{PUBLIC_KEY}", File.read(public_key))
  else
    puts "Cannot find public key file at #{public_key}"
  end
end