The template file is in the templates directory under the puppet module ". erb. The puppet template is mainly used for files, such as configuration files of various services. For the same service, you can consider using the template file for different configurations, for example, you can use the ERB template for nginx and Apache Virtual Host Configuration. We recommend that you use the yum source in the system to install nginx or other third-party Yum sources, if you use the official nginx source to install nginx, you can check/etc/yum. repos. d/nginx. the repo file content is as follows:
[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1
The second method is to use createrepo to build your own Yum source. This method is even better. We can download the suitable RPM package on the official nginx website and add it to our Yum source, in a custom environment with strict requirements for automated O & M, most O & M personnel choose this method. After installing nginx in this way, you will find that it is much easier to install nginx than the source code. For example, if nginx is automatically allocated to the user who runs nginx: nginx, nginx logs are automatically stored in/var/log/nginx, and the working directory is/etc/nginx.
I skipped other elementary knowledge points like puppet. I directly pasted the file content. The file structure of/etc/puppet is as follows:
|-- auth.conf|-- fileserver.conf|-- manifests| |-- nodes| | |-- client.cn7788.com.pp| | `-- test.cn7788.com.pp| `-- site.pp|-- modules| `-- nginx| |-- files| |-- manifests| | `-- init.pp| `-- templates| |-- nginx.conf.erb| `-- nginx_vhost.conf.erb`-- puppet.conf
The file content of site. PP is as follows:
import "nodes/*.pp"
The contents of client.cn7788.com. PP are as follows:
node ‘client.cn7788.com‘ { include nginx nginx::vhost {‘client.cn7788.com‘: sitedomain => "client.cn7788.com" , rootdir => "client",}}
The content of the file test.cn7788.com. PP is as follows:
node ‘test.cn7788.com‘ { include nginx nginx::vhost {‘test.cn7788.com‘: sitedomain => "test.cn7788.com" , rootdir => "test",}}
The/etc/puppet/modules/nginx/manifests/init. PP file is as follows:
class nginx{ package{"nginx": ensure =>present,} service{"nginx": ensure =>running, require =>Package["nginx"],}file{"nginx.conf":ensure => present,mode => 644,owner => root,group => root,path => "/etc/nginx/nginx.conf",content=> template("nginx/nginx.conf.erb"),require=> Package["nginx"],}}define nginx::vhost($sitedomain,$rootdir) { file{ "/etc/nginx/conf.d/${sitedomain}.conf": content => template("nginx/nginx_vhost.conf.erb"), require => Package["nginx"], }}
The/etc/puppet/modules/nginx/templates/nginx. conf. ERB file is as follows:
user nginx;worker_processes 8;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { use epoll; worker_connections 51200;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf;}
The/etc/puppet/modules/nginx/templates/nginx_vhost.conf.erb file is as follows:
server { listen 80;server_name <%= sitedomain %>;access_log /var/log/nginx/<%= sitedomain %>.access.log;location / {root /var/www/<%= rootdir %>;index index.php index.html index.htm;}}
This article from the "fuqin liquor" blog, please be sure to keep this source http://yuhongchun.blog.51cto.com/1604432/1569791
Use the ERB template in puppet to automatically configure the nginx Virtual Host