通过配置ssh深刻理解puppet的语法及工作机制

通过配置ssh深刻理解puppet的语法及工作机制


需求分析

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'
                }
                /^(RedHat|CentOS|Fedora)$/: {
                        $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'
                }
        }

}

创建测试文件
[root@puppetserver manifests]# mkdir /etc/puppet/modules/ssh/files/etc/ssh/ -p [root@puppetserver manifests]# scp agent1.rsyslog.org:/etc/ssh/sshd_config /etc/puppet/modules/ssh/files/etc/ssh/ 
[root@puppetserver ~]# service puppetmaster reload

测试(puppet kick的方式)

Puppet server端开启调试模式测试
[root@puppetserver ~]# puppet master --no-daemonize --verbose 

Puppet agent端开启调试模式测试
[root@puppetserver manifests]# puppetrun -p 10 --host agent1.rsyslog.org
Triggering agent1.rsyslog.org
Getting status
status is success
agent2.rsyslog.org finished with exit code 0
Finished

 新开自动化运维管理群:296934942欢迎各界大牛加入探讨!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值