通过配置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,如需转载请自行联系原作者

相关文章
|
2月前
|
网络安全 开发工具 git
GitHub 多账户 SSH 配置指南
本文介绍了如何在同一台电脑上配置多个 GitHub 账户的 SSH 密钥。内容包括:检查现有密钥、生成新的 SSH 密钥、配置 SSH config 文件、将公钥添加到 GitHub、验证 SSH 连接、设置 Git 用户信息、创建工作区目录、使用不同账户克隆仓库,以及为每个仓库配置独立的用户信息等步骤。通过这些操作,可以实现在不同项目中使用不同的 GitHub 账户进行提交和管理。
232 0
|
11月前
|
运维 Linux Apache
Puppet 作为一款强大的自动化运维工具,被广泛应用于配置管理领域。通过定义资源的状态和关系,Puppet 能够确保系统始终处于期望的配置状态。
Puppet 作为一款强大的自动化运维工具,被广泛应用于配置管理领域。通过定义资源的状态和关系,Puppet 能够确保系统始终处于期望的配置状态。
347 3
|
5月前
|
安全 Linux 网络安全
在Linux(CentOS和AWS)上安装更新的git2的方法并配置github-ssh
经过以上这些步骤,你现在就能在GitHub上顺利往返,如同海洋中的航海者自由驰骋。欢迎你加入码农的世界,享受这编程的乐趣吧!
202 10
|
安全 网络协议 Shell
Github代码仓库SSH配置流程
这篇文章是关于如何配置SSH以安全地连接到GitHub代码仓库的详细指南,包括使用一键脚本简化配置过程、生成SSH密钥对、添加密钥到SSH代理、将公钥添加到GitHub账户以及测试SSH连接的步骤。
525 0
Github代码仓库SSH配置流程
|
监控 安全 Ubuntu
在Linux中,如何进行SSH服务配置?
在Linux中,如何进行SSH服务配置?
|
网络安全 开发工具 git
拉取 gitee 代码,配置SSH,Please make sure you have the correct access rights
拉取 gitee 代码,配置SSH,Please make sure you have the correct access rights
211 1
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
3240 0
|
Ubuntu Shell 网络安全
【Ubuntu】配置SSH
【Ubuntu】配置SSH
556 0
|
安全 Linux 网络安全
在Linux中,如何配置SSH以确保远程连接的安全?
在Linux中,如何配置SSH以确保远程连接的安全?
|
安全 Linux Shell
如何在 Linux 服务器上配置基于 SSH 密钥的身份验证
如何在 Linux 服务器上配置基于 SSH 密钥的身份验证
912 0