Skip to content

Instantly share code, notes, and snippets.

@justindossey
Created January 4, 2017 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justindossey/dddb2bef143fcacc90a480d174e12298 to your computer and use it in GitHub Desktop.
Save justindossey/dddb2bef143fcacc90a480d174e12298 to your computer and use it in GitHub Desktop.
custom fact with defined type
# Configure a serial port for IPMI (which provides virtual ones).
# Depends on the "serial_ports" custom fact, included in this module
define ipmi::serial {
include stdlib
include ipmi::serial_prerequisites
$port_exists = member($::serial_ports, "/dev/${title}")
if $port_exists {
service { $title:
ensure => running,
require => File["/etc/init/${title}.conf"],
}
file { "/etc/init/${title}.conf":
mode => '0644',
owner => 'root',
group => 'root',
content => template('ipmi/tty.conf.erb'),
notify => Service[$title],
}
} else {
service { $title:
ensure => stopped,
}
file { "/etc/init/${title}.conf":
ensure => absent,
require => Service[$title],
}
}
}
# return a list of the active serial ports on this host
module Serial
def self.add_facts
Facter.add(:serial_ports) do
confine :kernel => 'Linux'
setcode do
ports = Dir.glob('/dev/ttyS*').join(' ')
setserial = '/bin/setserial'
get_active_ports = "#{setserial} -g #{ports} |sed '/unknown/d;s/,.*//'"
Facter::Core::Execution.exec(get_active_ports).split
end
end
end
end
Serial.add_facts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment