通过配置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



本文转自凌激冰51CTO博客,原文链接:http://blog.51cto.com/dreamfire/1257719,如需转载请自行联系原作者

相关文章
|
1月前
|
安全 网络协议 Shell
Github代码仓库SSH配置流程
这篇文章是关于如何配置SSH以安全地连接到GitHub代码仓库的详细指南,包括使用一键脚本简化配置过程、生成SSH密钥对、添加密钥到SSH代理、将公钥添加到GitHub账户以及测试SSH连接的步骤。
38 0
Github代码仓库SSH配置流程
|
1月前
|
网络安全 开发工具 git
拉取 gitee 代码,配置SSH,Please make sure you have the correct access rights
拉取 gitee 代码,配置SSH,Please make sure you have the correct access rights
37 1
|
1月前
|
Shell 网络安全 开发工具
Gerrit✨Gerrit服务器简介 与 配置SSH keys
Gerrit✨Gerrit服务器简介 与 配置SSH keys
|
30天前
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
52 0
|
1月前
|
Ubuntu Shell 网络安全
【Ubuntu】配置SSH
【Ubuntu】配置SSH
46 0
|
1月前
|
安全 Linux 网络安全
在Linux中,如何配置SSH以确保远程连接的安全?
在Linux中,如何配置SSH以确保远程连接的安全?
|
1月前
|
安全 Linux Shell
如何在 Linux 服务器上配置基于 SSH 密钥的身份验证
如何在 Linux 服务器上配置基于 SSH 密钥的身份验证
43 0
|
1月前
|
安全 Unix Shell
如何在 FreeBSD 服务器上配置基于 SSH 密钥的身份验证
如何在 FreeBSD 服务器上配置基于 SSH 密钥的身份验证
65 0
|
1月前
|
Linux 网络安全 数据安全/隐私保护
Linux——配置SSH免密登录
Linux——配置SSH免密登录
34 0
|
1月前
|
Linux 网络安全 数据安全/隐私保护
配置ssh免密登录
配置ssh免密登录