设为首页 收藏本站
查看: 1238|回复: 0

[经验分享] puppet资源类型详解(02)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-14 08:27:49 | 显示全部楼层 |阅读模式
常用的资源类型:
                        notify, cron, exec, service, file, package, group, user

(1) notify:利用puppet定义一个信息。
                                message:通知的信息内容
1
2
3
notify {'warning':
message=> "From warning notify resource.",
}




(2) cron
                                ensure: 目标状态
                                command: 命令
                                hour
                                minute
                                month
                                monthday
                                weekday
                                name: 名称
                                user: 接收此任务的用户
                                environment: 运行时的环境变量

1
2
3
4
5
6
cron {'message':
minute=> '*/10',
command=> '/bin/echo "puppet"',
name=> 'echo something',
ensure=> present,
}




(3) exec
                                command (NameVar):要执行命令;必须幂等的;
                                creates:此属性指定的文件不存在时才执行此资源;
                                onlyif: 此属性指定的测试条件返回成功状态码时,才运行此资源指定的命令;
                                unless: 此属性指定的测试条件返回错误状态码时,才运行此资源指定的命令;
                                user: 以此属性指定的用户身份运行资源指定的命令;

                                group:
                                path: 命令的搜索路径合集;
                                cwd:在此属性指定的路径下运行此命令;
                                refresh: 定义如何refresh此资源;当此exec资源接收到其它资源的事件通知时的默认行为是再运行一次此资源,refresh属性就用于改变这种默认行为;
                                refreshonly:仅在收到refresh通知时才执行此exec资源指定的命令;
                                timeout: 命令运行超时时长;
                                tries: 尝试运行的次数;
1
2
3
4
5
exec {'test':
command=> 'echo "hi from exec again" >> /tmp/hello.puppet',
path => '/bin:/sbin:/usr/bin:/usr/sbin',
unless=> 'test -f /tmp/hello.puppet',
}




                                注意:如果不指定path属性,则命令必须为绝对路径,且shell内建命令可能无法运行;

(4) file
                                content:直接给定文件内容;
                                source: 复制此属性指定的文件为此file定义的文件的内容;
                                recurse: 如果source指定的路径为目录可递归传输整个目录;true or false;

                                checksum: 指定使用何种方式检查文件内容是否发生改变;
                                ctime:
                                mtime:
                                ensure: 文件存在与否及其文件类型
    如果文件本来不存在是否要新建文件,可以设置的值是 absent和present,file和directory. 如果指定 present,就会检查该文件是否存在,如果不存在就新建该文件,如果指定是 absent, 就会删除该文件(如果recurse => true ,就会删除目录)
                                        file, directory, link, present, absent
                                target: 当ensure为link时,指定链接的源文件;
                                force:强制运行与否;
                                owner: 属主
                                group: 属组
                                links:复制时如何处理链接文件,follow, ignore, manage;
                                mode: 权限
                                path: NameVar,文件路径;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
file {'/tmp/mydir':
ensure=> directory,
}
file {'/tmp/mydir/test.txt':
content=> 'hello from file resource',
ensure=> file,
}
file {'/tmp/mydir/fstab.puppet':
source=> '/etc/fstab',
ensure=> file,
}
file {'/tmp/mydir/fstab.link':
target=> '/tmp/mydir/fstab.puppet',
ensure=> link,
}
file {'/tmp/pam.puppet':
source=> '/etc/pam.d',
recurse=> true,
ensure=> directory,
}




(5) group
                                name: 组名,NameVar
                                gid: GID
                                system: 是否为系统组;
1
2
3
4
group {'mygrp':
gid=> 2000,
system=> false,
}




(6) user
                                comment:注释
                                ensure:
                                expiry: 过期时间
                                gid: 基本组
                                groups: 附加组
                                managehome: 是否让家目录具有“可管理性”;
                                home: 家目录路径
                                shell: 默认shell;
                                system: 是否为系统用户;
                                uid: UID
                                name: NameVar,用户名;
                                password:密码
                                password_max_age:
                                password_min_age:

1
2
3
4
5
group {'mysql':
ensure=> present,
system=> true,
gid=> 306,
}



1
2
3
4
group {'dbusers':
ensure=> present,
gid=> 3306,
}



1
2
3
4
5
6
7
user {'mysql':
ensure=> present,
uid=> 306,
gid=> 306,
groups=> 'dbusers',
system=> true,
}




(7) package
                                ensure: present, absent, latest, installed或版本号;
                                name: 程序包名,NameVar;
                                source:程序包来源;
                                provider: 指定要使用包管理器;
1
2
3
package{'zsh':
ensure=> installed,
}



1
2
3
4
5
package{'nginx':
ensure=> installed,
provider => rpm,
source=> '/tmp/nginx-1.6.2-1.el6.ngx.x86_64.rpm',
}




(8) service
                                ensure:running, true; stopped, false;
                                enable: 是否开机自动启动;
                                hasrestart: 告诉puppet服务脚本是否运行使用“restart”参数;
                                hasstatus:告诉puppet服务脚本是否运行使用“status”参数;
                                name: 脚本名称;
                                path: 脚本查找路径
                                pattern: 指明搜索服务相关的进程的模式;用于当脚本不支持使用restart/status参数时帮助判定服务是否运行;
                                restart:手动指定用于服务“重启”的命令;
                                start:
                                stop:
                                status:
1
2
3
4
5
package{'nginx':
ensure=> installed,
provider => rpm,
source=> '/tmp/nginx-1.6.2-1.el6.ngx.x86_64.rpm',
}



1
2
3
4
5
file {'/etc/nginx/conf.d/default.conf':
ensure=> file,
source=> '/tmp/default.conf',
notify=> Service['nginx'],
}



1
2
3
4
5
file {'/etc/nginx/nginx.conf':
ensure=> file,
source=> '/tmp/nginx.conf',
notify=> Service['nginx'],
}



1
2
3
4
5
6
service{'nginx':
ensure=> running,
enable=> true,
require=> Package['nginx'],
restart=> '/etc/rc.d/init.d/nginx reload',
}





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-164106-1-1.html 上篇帖子: puppet基础概念入门(01) 下篇帖子: 给个中维世纪监控系统的下载地址,悬赏20分
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表