Get the App
SLTechnology News&Howtos  ›  Servers  › 

Puppet resources and dependencies and local testing

Shulou Source: shulou.com Published: 2022-06-03 08:16:29 11月14日 Update

one。 Local pp file test package {"nginx": # function: install nginx ensure= > latest,} service {"nginx": # function: start nginx And let the settings boot ensure= > running, enable= > true, restart = > "systemctl restart nginx.service", # restart subscribe = > file ["/ etc/nginx/nginx.conf"] only if notified or subscribed, # listen to the following service. If triggered, restart the nginx # test and conclude that if the new file already exists in advance, it has not been modified. Restarting nginx will not be triggered. } file {"/ etc/nginx/nginx.conf": # function: copy nginx configuration file ensure= > file, content= > template ("/ root/nginx.conf"),}

Puppet apply-v-- noop cs.pp # test run, not really installed, used to read errors

Puppet apply-v cs.pp # actually runs the installation

two。 Dependence of resources

Before: indicates that you need to rely on a resource

Require: indicates that this resource should be executed first and other resources should be executed

Notify:A notify BRV B depends on An and notifies B when A changes

Subscribe:B subscribe avatar B depends on A, and B monitors events resulting from changes in A resources

Subscribe example:

Package {"httpd": ensure= > present,subscribe = > package ["nginx"], # means to subscribe to the following resource. If the following resource is not executed successfully, the resource will not be executed, and the following resource has been executed successfully or is already in the state of finished execution. This resource will execute} package {"nginx": ensure= > present,} notify example: package {"httpd": ensure= > present,} package {"nginx": ensure= > present,notify= > package ["httpd"], # indicates that the resource has been executed and notifies the above resource that the resource is not executed successfully The above resource will not execute} dependencies can also be sorted using-> and ~ > for example: exec {"echo'1' > > / root/2333.txt": path = > ["/ usr/bin", "/ usr/sbin"],} exec {"echo'2' > > / root/2333.txt": path = > ["/ usr/bin", "/ usr/sbin"],} exec {"echo'3' > > / root/2333.txt": path = > ["/ usr/bin" "/ usr/sbin"],} exec ["echo'3' > > / root/2333.txt"]-> exec ["echo'2' > > / root/2333.txt"]-> exec ["echo'1' > > / root/2333.txt"] if it is normal, the output should be 123 But I use the-> symbol to define the running order, and the final output is

three。 Introduction of several commonly used resources

1.exec resource exec {"mkdir 666": # command cwd = > "/ root/", # execute the command in that path, give creates = > "/ root/678" if the path does not exist, # judge, if you have this folder, you will not execute the path = > ["/ usr/bin", "/ usr/sbin"] # command program Go to that path to find the execution file} 2.package (installation software) package {["httpd.x86_64", "nginx.x86_64"]: # to separate multiple installable software ensure = > purged, # latest install the latest, installed installation Purged delete package provider = > "yum", # install in yum source in yum mode} package {"nginx": ensure = > installed, provider = > "rpm", # install as rpm local file, you must specify the path to the installation file below Otherwise, source = > "/ root/nginx-1.8.1-1.el7.ngx.x86_64.rpm"} 3.service and flieclass xingjian {service {"nginx": ensure = > running, # set to what state running is running, stopped stop status enable = > true, # whether to enable self-starting true Yes, false No hasrestart = > true, hasstatus = > true, require = > file ['/ etc/nginx/nginx.conf'] # when executing a resource, first check whether the following resource executes} file {"/ etc/nginx/nginx.conf": # replication path ensure = > file, # file type File directly copies the original type. If you want to enter link, create a linked file, but if you want to create a linked file, the following source should be replaced with target. If you enter directory, you will copy the folder. Need to add recurse='true' implementation to copy source = > "/ root/nginx.conf", # source file path}} 4.cron (scheduled task) cron {"jihua": command = > "/ root/1.sh", # # path name of execution script or command path name ensure = > "present", # present add if the cron does not exist Absent delete minute = > "* / 5" if the cron exists and run it every # 5 minutes Same as crontab usage: target = > "root", # under which user to execute script} 5 user and group group {"yangzai": # group name ensure = > present, gid = > "2333", system = > false, whether # is a system group # members: member user } user {"yangzai": # username ensure = > present, system = > false, comment = > "233", # comment Generally describe what software to run shell = > "/ bin/bash", # default shell home = > "/ home/yangzai", # home directory path managehome = > true, # whether to create a home directory groups = > "yangzai" Uid = > "2333"} 7. Notify {"hello world":} # display information

Tags: Resources files paths runs commands software tests success roles status users folders directories types results scripts pathnames links subscriptions output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi macOS Shulou Technology OPPO Reno