Created
January 4, 2017 19:52
-
-
Save justindossey/dddb2bef143fcacc90a480d174e12298 to your computer and use it in GitHub Desktop.
custom fact with defined type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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], | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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