kingforce 发表于 2018-8-2 08:11:34

1.7-puppet配置模块

  定义模块管理
  *模块是puppet的配置单元,模块里面会包含类和资源。同步文件、远程执行命令、cron等叫做资源,都是通过模块来实现的。下面我们来写一个模块
  *服务端创建目录
  mkdir /etc/puppet/modules/testm这个目录名字可以随便定义,作为模块名字。然后继续创建模块对应的子目录 mkdir /etc/puppet/modules/testm/{files,manifests,templates}file里面存文件,可以留空,manifests里面是配置文件,templates里面是模块文件,可以为空
  *创建配置文件
  vim /etc/puppet/modules/testm/manifests/init.pp
  vimanifests/init.pp   //内容如下
  class testm{
  file {"/tmp/2.txt":    #送往客户端的文件名,属性和内容来源
  owner => "root",
  group => "root",
  mode => 0400,
  source => "puppet://$puppetserver/modules/testm/1.txt"
  }
  }
  说明:类名字也叫做testm, 类下面定义了一个资源file,文件名字叫做/tmp/2.txt ,owner,group,mode定义文件的属主、属组以及权限,source定义这个文件从哪里获取。 $puppetserver一会也要定义一下,这里指的是puppet server服务器上/etc/puppet/modules/testm/files/1.txt
  *下面要继续定义一个很关键的配置文件:
  vim/etc/puppet/manifests/site.pp   //内容如下
  $puppetserver = 'master.wyp.com'   #定义模块配置文件中的变量
  node 'client.wyp.com'{
  include testm
  }
  说明:$puppetserver 定义服务端的主机名,node后面为客户端的主机名,这里面定义该客户端要加载的模块
  配置完成后,在客户端执行命令:
  puppet agent --test--server=master.wyp.com   //如果客户端上启动了puppet服务,不用执行这命令,它也会自动同步的
页: [1]
查看完整版本: 1.7-puppet配置模块