【1】puppet笔记 - file资源

puppet使用file资源能够对文件进行管理,能够对文件的内容、权限等管理。html


定义一个资源,须要指定资源的类型和资源的title。linux


file资源语法:
app

file {
        "/puppet/file/abc":
        name=> "/puppet/file/abc",
        content=>"test\n",
        owner=> root,
        mode=> 777;
}

第一行:指定资源是file类型

ide

第二行:资源title,默认是与name的值同样。this


执行后,会在/puppet/file目录下面建立abc文件,内容:test(换行),属于root用户,文件权限:777spa


file类型:操作系统

http://docs.puppetlabs.com/references/latest/type.html#file


file { 'resource title':
  path                    => # (namevar) The path to the file to manage.  Must be fully...
  ensure                  => # Whether the file should exist, and if so what...
  backup                  => # Whether (and how) file content should be backed...
  checksum                => # The checksum type to use when determining...
  content                 => # The desired contents of a file, as a string...
  ctime                   => # A read-only state to check the file ctime. On...
  force                   => # Perform the file operation even if it will...
  group                   => # Which group should own the file.  Argument can...
  ignore                  => # A parameter which omits action on files matching
  links                   => # How to handle links during file actions.  During
  mode                    => # The desired permissions mode for the file, in...
  mtime                   => # A read-only state to check the file mtime. On...
  owner                   => # The user to whom the file should belong....
  provider                => # The specific backend to use for this `file...
  purge                   => # Whether unmanaged files should be purged. This...
  recurse                 => # Whether and how to do recursive file management.
  recurselimit            => # How deeply to do recursive management.  Values...
  replace                 => # Whether to replace a file or symlink that...
  selinux_ignore_defaults => # If this is set then Puppet will not ask SELinux...
  selrange                => # What the SELinux range component of the context...
  selrole                 => # What the SELinux role component of the context...
  seltype                 => # What the SELinux type component of the context...
  seluser                 => # What the SELinux user component of the context...
  show_diff               => # Whether to display differences when the file...
  source                  => # A source file, which will be copied into place...
  source_permissions      => # Whether (and how) Puppet should copy owner...
  sourceselect            => # Whether to copy all valid sources, or just the...
  target                  => # The target for creating a link.  Currently...
  type                    => # A read-only state to check the file...
  validate_cmd            => # A command for validating the file's syntax...
  validate_replacement    => # The replacement string in a `validate_cmd` that...
  # ...plus any applicable metaparameters.
}



ensure=>values
present:文件不存在,会自动建立
absent:删除存在的文件
directory:建立一个目录
link:连接文件


(file资源的文件,须要前面的路径是存在的,以下面的/puppet/file目录是存在的)日志

一、建立普通文件component

在puppet/file目录建立文件名:1,内容为当前操做系统名称。orm

注:如果建立新文件,只要content有值,那么能够不须要ensure=>present。

file {
        "/puppet/file/1":
        ensure=>present,
        content => $operatingsystem,
        owner => root,
        mode => 644;
}

二、建立目录


file {
        "/puppet/file/mulu":
        ensure=>directory,
        mode=>644;
}


三、建立连接


file {
        "/puppet/file/link":
        ensure=>link,
        target=>"/etc/passwd";
}

四、删除文件

file {
        "/puppet/file/1":
        ensure=>absent,
        content => $operatingsystem,
        owner => root,
        mode => 644;
}




客户端能够直接运行本地manifest,命令:puppet apply -l /var/log/puppet/a.log 1.pp


[root@pclient test]# puppet apply -l /var/log/puppet/a.log 1.pp
Puppet apply 运行本地manifests
/var/log/puppet/ 这个目录是在/etc/puppet.conf配置  a.log自定义




执行后查看/var/log/puppet/a.log看到如下日志

Mon Apr 14 15:54:58 +0800 2014 Puppet (notice): Compiled catalog for pclient.onepc.com in environment production in 0.12 seconds
Mon Apr 14 15:54:59 +0800 2014 /Stage[main]/Main/File[/puppet/file/1]/ensure (notice): created
Mon Apr 14 15:54:59 +0800 2014 /Stage[main]/Main/File[/puppet/file/link]/ensure (notice): created
Mon Apr 14 15:54:59 +0800 2014 /Stage[main]/Main/File[/puppet/file/mulu]/ensure (notice): created
Mon Apr 14 15:54:59 +0800 2014 Puppet (notice): Finished catalog run in 0.11 seconds


[root@pclient file]# ll
总用量 8
-rw-r--r-- 1 root root    6  4月 14 15:54 1
lrwxrwxrwx 1 root root   11  4月 14 15:54 link -> /etc/passwd
drwxr-xr-x 2 root root 4096  4月 14 15:54 mulu
[root@pclient file]#
相关文章
相关标签/搜索