1)、要求openssh-server处于被安装状态
2)、要求在配置文件/etc/ssh/sshd_config正确的情况下,sshd服务处于运行状态
2)、要求/etc/ssh/sshd_config文件属性不被串改(权限、属主、属组等)
3)、要求/etc/ssh/sshd_config文件被修改或者删除后会被自动修复
4)、要求通过puppetserver端修改/etc/ssh/sshd_config之后,sshd服务能够自动重启。
定义全局配置信息
定义全局配置文件site.pp
[root@puppetserver ~]# vim /etc/puppet/manifests/site.pp
import 'nodes/*'
$puppetserver = 'puppetserver.rsyslog.org'
创建并配置nodes.pp节点
[root@puppetserver ~]# mkdir /etc/puppet/manifests/nodes –p
[root@puppetserver ~]# vim /etc/puppet/manifests/nodes/nodes.pp
> node /^agent\d+\.rsyslog.org$/{
> include ssh
> }
> endf
设置模块搜索路径
vim /etc/puppet/puppet.conf
[main]
modulepath = /etc/puppet/modules:/var/lib/puppet/modules:/usr/local/lib/puppet/modules
创建模块目录结构
[root@puppetserver ~]# mkdir -vp
/etc/puppet/modules/ssh/{files,templates,manifests}
创建配置文件
创建配置文件(/etc/puppet/modules/ssh/manifests目录下)
1)、创建site.pp文件
class ssh{
include ssh::params,ssh::config,ssh::service,ssh::install
}
2)、创建install.pp文件
class ssh::install{
package { $ssh::params::ssh_package_name:
ensure => installed,
}
}
3)、创建config.pp文件
class ssh::config{
file { $ssh::params::ssh_service_config:
ensure => present,
owner => 'root',
group => 'root',
mode => 0440,
source => "puppet:///modules/ssh/etc/ssh/sshd_config",
require => Class["ssh::install"],
notify => Class["ssh::service"],
}
}
4)、创建service.pp文件
class ssh::service{
service { $ssh::params::ssh_service_name:
ensure => running,
hasstatus => true,
hasrestart => true,
enable => true,
require => Class["ssh::config"],
}
}
5)、创建params.pp文件
class ssh::params {
case $::operatingsystem {
Slaris: {
$ssh_package_name = 'openssh'
$ssh_service_config = '/etc/ssh/sshd_config'
$ssh_service_name = 'sshd'
}
/^(Ubuntu|Debian)$/: {
$ssh_package_name = 'openssh-server'
$ssh_service_config = '/etc/ssh/sshd_config'
$ssh_service_name = 'sshd'
}
/^()$/: {
$ssh_package_name = 'openssh-server'
$ssh_service_config = '/etc/ssh/sshd_config'
$ssh_service_name = 'sshd'
}
default: {
$ssh_package_name = 'openssh-server'
$ssh_service_config = '/etc/ssh/sshd_config'
$ssh_service_name = 'sshd'
}
}
}