使用git管理puppet运行环境与配置版本
来源:互联网 发布:cad 2016 mac序列号 编辑:程序博客网 时间:2024/05/29 18:09
一、Puppet运行环境
在运维工作中需要同时处理开发、测试和生产等多套运行环境时,可以使用Puppet的环境配置选项{environment},并结合指定自定义的变量配置。
- 修改puppet.conf增加环境的配置
Puppet默认是以生产环境运行的(即main),可以按需进行重新定义一种或几种运行环境。
在配置环境变量时,还可以自定义site.pp的位置、模块目录能主文件目录,以区分几种运行环境。
例如:$vim /etc/puppet/puppet.conf[master]environment = testing,production[testing]manifest = /etc/puppet/manifests/testing/site.ppmodulepath = /etc/puppet/modules/testingfileserverconfig = /etc/puppet/fileserver.conf.testing[production]manifest = /etc/puppet/manifests/production/site.ppmodulepath = /etc/puppet/modules/productionfileserverconfig = /etc/puppet/fileserver.conf.production
重启Puppet以使配置生效:
service puppetmaster restart - 客户端的运行环境配置
方法一:修改配置文件puppet.conf,增加选项
[agent]
environment = testing
方法二:使用命令行参数
$puppet agent --test --noop --environment testing
二、使用git配合Puppet实现多环境的配置操作
1、安装git
安装git,创建项目目录puppet.git。
采用daemon方式启动git。
在/tmp下创建git管理目录puppet。
采用git管理/etc/puppet目录。
#yum -y install git git-daemon
创建puppet repo目录:
#mkdir -p /tmp/puppet_repo/puppet.git
创建git仓库:
#cd /tmp/puppet_repo/puppet.git
#git --bare init
设置目录访问权限:
# chown -R daemon.daemon /tmp/puppet_repo/
采用git daemon的方式启动服务:
# git daemon --base-path=/tmp/puppet_repo/ --detach --user=daemon --listen=127.0.0.1 --group=daemon --export-all --enable=receive-pack --enable=upload-pack --enable=upload-archive
2、将/etc/puppet划归git管理
首先在/tmp中创建puppet的临时仓库:
#cd /tmp
#git clone git://127.0.0.1/puppet.git puppet
将puppet配置文件复制到临时仓库:
[root@puppet tmp]# cp -r /etc/puppet/* /tmp/puppet
将puppet添加到仓库:
[root@puppet tmp]# cd /tmp/puppet
[root@puppet puppet]# git add -A
配置commit添加:
[root@puppet puppet]# git commit -m "Add Puppet to Git."[master (root-commit) 64f23a3] Add Puppet to Git.Committer: root <root@puppet.jrtoo.com> 9 files changed, 219 insertions(+), 0 deletions(-)create mode 100644 auth.confcreate mode 100644 environments/example_env/README.environmentcreate mode 100644 fileserver.confcreate mode 100644 manifests/nodes/compute5.jrtoo.com.ppcreate mode 100644 manifests/site.ppcreate mode 100644 modules/httpd/manifests/init.ppcreate mode 100644 modules/test/manifests/init.ppcreate mode 100644 modules/test/templates/test.erbcreate mode 100644 puppet.conf
提交至版本库主分支:
[root@puppet puppet]# git push origin masterCounting objects: 21, done.Delta compression using up to 4 threads.Compressing objects: 100% (13/13), done.Writing objects: 100% (21/21), 4.30 KiB, done.Total 21 (delta 0), reused 0 (delta 0)To git://127.0.0.1/puppet.git* [new branch] master -> master
删除Master节点的/etc/puppet目录,并使用git克隆下来:
[root@puppet puppet]# rm -rf /etc/puppet[root@puppet puppet]# cd /etc[root@puppet etc]# git clone git://127.0.0.1/puppet.gitInitialized empty Git repository in /etc/puppet/.git/remote: Counting objects: 21, done.remote: Compressing objects: 100% (13/13), done.remote: Total 21 (delta 0), reused 0 (delta 0)Receiving objects: 100% (21/21), 4.30 KiB, done.[root@puppet etc]# ls puppet/auth.conf environments fileserver.conf manifests modules puppet.conf3、创建testing分支并提交新的修改
git branch 查看当前分支
创建并切换至testing分支:
git checkout -b testing
修改httpd类并增加File资源:
vim /etc/puppet/modules/httpd/manifests/init.pp
file { "/tmp/puppettesting.txt" : content => "Hello,Puppet environments testing."; }
自动检查应该commit什么文件:
git commit -a 'hello,testing puppet enviironments.'
提交到origin这个远端树的testing分支:
git push origin testing
使用puppet客户端验证以上配置是否有效:
puppet agent --test --noop --environment testing --server puppet.jrtoo.com
注:在使用puppet3.8.4进行以上测试时,发现puppet.conf文件中创建自定义的运行环境参数的做法已经被废弃,不建议使用。但是上文中涉及到的使用git创建版本库管理puppet配置的方法是完全正确且可用的。
Reference from 《Puppet in action》
0 0
- 使用git管理puppet运行环境与配置版本
- fedora10 使用Git管理版本配置
- 使用git管理服务器开发环境配置
- puppet 管理配置索引
- Git版本管理:Windows下Git配置与使用指南
- 使用GIT管理版本
- Git版本管理使用
- 【版本管理】Git使用
- 创建Git版本管理环境
- puppet 配置 3.4 文件管理与自定义模块
- puppet命令与配置
- puppet 安装与配置
- puppet 配置 3.2 管理 hosts
- puppet 配置 - 3.3 rpm 管理
- Eclipse使用Git代替CVS与SVN实现版本管理
- Eclipse使用Git代替CVS与SVN实现版本管理
- Eclipse使用Git代替CVS与SVN实现版本管理
- Eclipse使用Git代替CVS与SVN实现版本管理
- 探索设计模式之六——单例模式
- Ry’s Objective-C Tutorial---Blocks
- 数据存储
- Ry’s Objective-C Tutorial---Exceptions & Errors
- EasyUI常用控件的禁用方法
- 使用git管理puppet运行环境与配置版本
- 浅谈对象和过程
- 数据库之SQL基本语法
- 约瑟夫环的list递归和链表两种实现(java)
- Ry’s Objective-C Tutorial---Memory Management
- NDK初识
- LintCode-剑指Offer-(68)二叉树的后序遍历
- ubuntu14.04,安装VirtualBox 5.0(虚拟机软件)!
- Ry’s Objective-C Tutorial---Objective-C Data Types