太懒
分类: LINUX
2013-05-28 10:53:29
参考:
新建两个文件
vimrc
set t_Co=256
set nu
set background=dark
colorscheme pablo
syntax on
bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'#vim
alias vi='vim'# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
放到 agent的/etc/skel 目录下,新建用户的时候自动拷贝到用户主目录
1.创建module
经常做的事情,能写成脚本就写成脚本
createmodule.sh
#!/bin/bash
. /etc/profile
echo "this script used to create the default directory structure"
echo ""
echo "current directory is :"
echo ""
echo ${PWD}
echo ""
#echo ${0}
echo "if ture please enter 1 other please enter 2"
read userResult
echo ""echo "please enter module name!"
read moduleNamecreateDict() {
echo "create the default directory structure for puppet modules"
#echo "${PWD}/${moduleName}/files"
mkdir -p ${PWD}/${moduleName}/{files,templates,manifests}
touch ${PWD}/${moduleName}/manifests/init.pp
}
case $userResult in
1)
createDict
;;
2)
exit 1
;;
esac
[root@my2950 modules]# ./createmodule.sh
this script used to create the default directory structurecurrent directory is :
/etc/puppet_sotre/develop/modules
if ture please enter 1 other please enter 2
1please enter module name!
myadduser
create the default directory structure for puppet modules
[root@my2950 modules]# ll
total 20
drwxr-xr-x 5 root root 4096 May 27 17:41 myadduser
-rwxr--r-- 1 root root 648 May 27 17:37 createmodule.sh
drwxr-xr-x 5 root root 4096 May 24 16:46 dnsclient
drwxr-xr-x 5 root root 4096 May 24 16:46 mycrond
drwxr-xr-x 5 root root 4096 May 24 16:46 myvimrc
[root@my2950 modules]# tree myadduser/
myadduser/
├── files
├── manifests
│ └── init.pp
└── templates3 directories, 1 file
[root@my2950 modules]#vimrc 放到 ./myadduser/templates/ 目录下
bashrc 放到 ./myadduser/files/ 目录下
[root@my2950 modules]# ls ./myadduser/
files/ manifests/ templates/
[root@my2950 modules]# ls ./myadduser/templates/
[root@my2950 modules]# vi ./myadduser/templates/vimrc
[root@my2950 modules]# vi ./myadduser/files/bashrc
[root@my2950 modules]# more ./myadduser/templates/vimrc
set t_Co=256
set nu
set background=dark
colorscheme pablo
syntax on[root@my2950 modules]# more ./myadduser/files/bashrc
# .bashrc# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'#vim
alias vi='vim'# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi[root@my2950 modules]#
[root@my2950 modules]# tree myadduser/
myadduser/
├── files
│ └── bashrc
├── manifests
│ └── init.pp
└── templates
└── vimrc3 directories, 3 files
[root@my2950 modules]#
2. 编辑 init.pp
vi myadduser/manifests/init.pp
class myadduser {
include adduser::vimrc,adduser::bashrc
}class adduser::vimrc {
file { "/etc/skel/.vimrc":
content => template("myadduser/vimrc"),
}
}class adduser::bashrc {
file { "/etc/skel/.bashrc":
source => puppet:///modules/myadduser/bashrc
backup => main,
checksum => md5,
ensure => file,
owner => 'root',
group => 'root',
mode => 0644,
}
}
[root@my2950 modules]# tree myadduser/
myadduser/
├── files
│ └── bashrc
├── manifests
│ └── init.pp
└── templates
└── vimrc3 directories, 3 files
[root@my2950 modules]#
3. 提交到中心库
[root@my2950 develop]# pwd
/etc/puppet_sotre/develop
[root@my2950 develop]# git status
# On branch master
# Untracked files:
# (use "git add..." to include in what will be committed)
#
# modules/createmodule.sh
# modules/myadduser/
nothing added to commit but untracked files present (use "git add" to track)
[root@my2950 develop]# git add .
[root@my2950 develop]# git commit -a -m "create myadduser"
[master 3e67c4e] create myadduser
4 files changed, 81 insertions(+)
create mode 100755 modules/createmodule.sh
create mode 100644 modules/myadduser/files/bashrc
create mode 100644 modules/myadduser/manifests/init.pp
create mode 100644 modules/myadduser/templates/vimrc
[root@my2950 develop]# git push
Counting objects: 13, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (11/11), 1.39 KiB, done.
Total 11 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.
To /var/ftp/pub/mygit/puppet.store
2ae13c2..3e67c4e master -> master
[root@my2950 develop]#
4. 测试环境检出测试
[root@my2950 develop]# cd ../testing/
[root@my2950 testing]# pwd
/etc/puppet_sotre/testing
[root@my2950 testing]# ls
manifests modules
[root@my2950 testing]#[root@my2950 testing]# ls modules/
dnsclient mycrond myvimrc
[root@my2950 testing]# git pull
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 11 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.
From /var/ftp/pub/mygit/puppet.store
2ae13c2..3e67c4e master -> origin/master
Updating 2ae13c2..3e67c4e
Fast-forward
modules/createmodule.sh | 35 +++++++++++++++++++++++++++++++++++
modules/myadduser/files/bashrc | 18 ++++++++++++++++++
modules/myadduser/manifests/init.pp | 22 ++++++++++++++++++++++
modules/myadduser/templates/vimrc | 6 ++++++
4 files changed, 81 insertions(+)
create mode 100755 modules/createmodule.sh
create mode 100644 modules/myadduser/files/bashrc
create mode 100644 modules/myadduser/manifests/init.pp
create mode 100644 modules/myadduser/templates/vimrc
[root@my2950 testing]#
[root@my2950 testing]# ls modules/
createmodule.sh dnsclient myadduser mycrond myvimrc
[root@my2950 testing]#
切换到测试机上
[root@node1 skel]# pwd
/etc/skel
[root@node1 skel]# ls -al
total 40
drwxr-xr-x. 4 root root 4096 May 22 11:58 .
drwxr-xr-x. 101 root root 12288 May 27 15:16 ..
-rw-r--r--. 1 root root 18 Dec 20 13:26 .bash_logout
-rw-r--r--. 1 root root 176 Dec 20 13:26 .bash_profile
-rw-r--r--. 1 root root 124 Dec 20 13:26 .bashrc
drwxr-xr-x. 2 root root 4096 Nov 20 2010 .gnome2
-rw-r--r--. 1 root root 121 Dec 21 02:32 .kshrc
drwxr-xr-x. 4 root root 4096 May 22 11:47 .mozilla
[root@node1 skel]# more .bashrc
# .bashrc# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi# User specific aliases and functions
puppet agent --server my2950.momo.org --noop --test --environment testing
puppet agent --server my2950.momo.org --environment testing --noop –testpuppet agent --server my2950.momo.org --environment testing –noop
puppet agent --server my2950.momo.org --environment testing --no-daemonize --verbose –onetimepuppet agent --server my2950.momo.org --environment testing --no-daemonize --verbose –onetime –noop[root@node1 skel]# puppet agent --server my2950.momo.org --environment testing --no-daemonize --verbose --onetime
info: Caching catalog for node1.momo.org
info: Applying configuration version '1369704619'
notice: Finished catalog run in 0.10 seconds
[root@node1 skel]# ls -al
total 40
drwxr-xr-x. 4 root root 4096 May 22 11:58 .
drwxr-xr-x. 101 root root 12288 May 27 15:16 ..
-rw-r--r--. 1 root root 18 Dec 20 13:26 .bash_logout
-rw-r--r--. 1 root root 176 Dec 20 13:26 .bash_profile
-rw-r--r--. 1 root root 124 Dec 20 13:26 .bashrc
drwxr-xr-x. 2 root root 4096 Nov 20 2010 .gnome2
-rw-r--r--. 1 root root 121 Dec 21 02:32 .kshrc
drwxr-xr-x. 4 root root 4096 May 22 11:47 .mozilla
[root@node1 skel]#没生效,怎么回事?
原来上忘了修改site.pp,回到server端
5. 修改 site.pp
develop
[root@my2950 develop]# pwd
/etc/puppet_sotre/develop
[root@my2950 develop]# ll
total 8
drwxr-xr-x 3 root root 4096 May 24 17:06 manifests
drwxr-xr-x 6 root root 4096 May 27 18:23 modules
[root@my2950 develop]# vi manifests/
node.pp nodes/ site.pp[root@my2950 develop]# vi manifests/node.pp
[root@my2950 develop]#
[root@my2950 develop]#
[root@my2950 develop]# more manifests/node.pp
node 'resource.qilinsoft.com' {
#include aaa
#include bbb
#include aaa,bbb
include dnsclient
include mycrond
}node 'node1.hjshi.com' {
include myvimrc
}node /^node\d+\.momo\.org/ {
include myvimrc
include dnsclient
include mycrond
include myadduser
}[root@my2950 develop]#
提交到中心库
[root@my2950 develop]# git status
# On branch master
# Changes not staged for commit:
# (use "git add..." to update what will be committed)
# (use "git checkout --..." to discard changes in working directory)
#
# modified: manifests/node.pp
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@my2950 develop]# git commit -a -m "modify node.pp myadduser"
[master 4d15552] modify node.pp myadduser
1 file changed, 1 insertion(+)
[root@my2950 testing]# git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 428 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
To /var/ftp/pub/mygit/puppet.store
3e67c4e..4d15552 master –> master[root@my2950 develop]# cd ../testing/
[root@my2950 testing]# pwd
/etc/puppet_sotre/testing
[root@my2950 testing]# git pull
Already up-to-date.
[root@my2950 testing]#转到step4 继续测试
[root@node1 skel]# puppet agent --server my2950.momo.org --environment testing --no-daemonize --verbose --onetime
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at ':'; expected '}' at /etc/puppet_sotre/testing/modules/myadduser/manifests/init.pp:13 on node node1.momo.org
notice: Using cached catalog
info: Applying configuration version '1369705189'
notice: Finished catalog run in 0.03 secondssource => puppet:///modules/myadduser/bashrc
source => "puppet:///modules/myadduser/bashrc",
[root@node1 skel]# puppet agent --server my2950.momo.org --environment testing --no-daemonize --verbose --onetime
info: Caching catalog for node1.momo.org
err: Failed to apply catalog: Could not find filebucket main specified in backup at /etc/puppet_sotre/testing/modules/myadduser/manifests/init.pp:21
[root@node1 skel]#修改server端 /etc/puppet_sotre/develop/manifests/site.pp
添加:
# /etc/puppet/manifests/site.pp
filebucket {
'main':
path => false, # This is required for remote filebuckets. Default:$vardir/bucket
server => 'my2950.momo.org', # Optional; defaults to the configured puppet master.
}检出
[root@my2950 develop]# git status
# On branch master
# Changes not staged for commit:
# (use "git add..." to update what will be committed)
# (use "git checkout --..." to discard changes in working directory)
#
# modified: manifests/site.pp
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@my2950 develop]# git commit -a -m "modify site.pp add filebucker"
[master b83ebc1] modify site.pp add filebucker
1 file changed, 7 insertions(+)
[root@my2950 develop]#
[root@my2950 develop]# git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 534 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
To /var/ftp/pub/mygit/puppet.store
1a23e07..b83ebc1 master -> master
[root@my2950 develop]#
[root@my2950 develop]# cd ../testing/[root@my2950 testing]# git status
# On branch master
nothing to commit (working directory clean)
[root@my2950 testing]# git pull
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From /var/ftp/pub/mygit/puppet.store
1a23e07..b83ebc1 master -> origin/master
Updating 1a23e07..b83ebc1
Fast-forward
manifests/site.pp | 7 +++++++
1 file changed, 7 insertions(+)
[root@my2950 testing]#
agent端重新测试
[root@node1 skel]# puppet agent --server my2950.momo.org --environment testing --no-daemonize --verbose --onetime
info: Caching catalog for node1.momo.org
info: Applying configuration version '1369707060'
notice: /Stage[main]/Adduser::Vimrc/File[/etc/skel/.vimrc]/ensure: defined content as '{md5}65a3340a77d8841ec023b64c96e31984'
info: /Stage[main]/Adduser::Bashrc/File[/etc/skel/.bashrc]: Filebucketed /etc/skel/.bashrc to main with sum f119c865306c35e64eb00f65d7279664
notice: /Stage[main]/Adduser::Bashrc/File[/etc/skel/.bashrc]/content: content changed '{md5}f119c865306c35e64eb00f65d7279664' to '{md5}55b7566ba6c577732230c1ad24156f29'
notice: Finished catalog run in 1.04 seconds
[root@node1 skel]#
[root@node1 skel]# pwd
/etc/skel
[root@node1 skel]#
[root@node1 skel]# ls -al
total 44
drwxr-xr-x. 4 root root 4096 May 28 10:10 .
drwxr-xr-x. 101 root root 12288 May 27 15:16 ..
-rw-r--r--. 1 root root 18 Dec 20 13:26 .bash_logout
-rw-r--r--. 1 root root 176 Dec 20 13:26 .bash_profile
-rw-r--r-- 1 root root 211 May 28 10:10 .bashrc
drwxr-xr-x. 2 root root 4096 Nov 20 2010 .gnome2
-rw-r--r--. 1 root root 121 Dec 21 02:32 .kshrc
drwxr-xr-x. 4 root root 4096 May 22 11:47 .mozilla
-rw-r--r-- 1 root root 69 May 28 10:10 .vimrc
[root@node1 skel]# more .vimrc
set t_Co=256
set nu
set background=dark
colorscheme pablo
syntax on[root@node1 skel]# more .bashrc
# .bashrc# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'#vim
alias vi='vim'# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi[root@node1 skel]#
5. 部署
[root@my2950 testing]# cd ../main
[root@my2950 main]# git status
# On branch master
nothing to commit (working directory clean)
[root@my2950 main]# git pull
remote: Counting objects: 32, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 27 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (27/27), done.
From /etc/puppet_sotre/./testing
2ae13c2..b83ebc1 master -> origin/master
Updating 2ae13c2..b83ebc1
Fast-forward
manifests/node.pp | 1 +
manifests/site.pp | 7 +++++++
modules/createmodule.sh | 35 +++++++++++++++++++++++++++++++++++
modules/myadduser/files/bashrc | 18 ++++++++++++++++++
modules/myadduser/manifests/init.pp | 23 +++++++++++++++++++++++
modules/myadduser/templates/vimrc | 6 ++++++
6 files changed, 90 insertions(+)
create mode 100755 modules/createmodule.sh
create mode 100644 modules/myadduser/files/bashrc
create mode 100644 modules/myadduser/manifests/init.pp
create mode 100644 modules/myadduser/templates/vimrc
[root@my2950 main]#
[root@my2950 ~]# cd /var/lib/puppet/bucket/
[root@my2950 bucket]# tree
.
└── f
└── 1
└── 1
└── 9
└── c
└── 8
└── 6
└── 5
└── f119c865306c35e64eb00f65d7279664
├── contents
└── paths9 directories, 2 files
[root@my2950 bucket]#
puppet 2.6 agent模式的report默认应该是 false ,必须在agent里显示声明一下server端才能收到report
puppet-2.6.18-3.el6.noarch
[root@node2 puppet]# rpm -qa|grep puppet
puppet-2.6.18-3.el6.noarch
[root@node2 puppet]#