Use Puppet to automatically install httpd to clients

Source: Internet
Author: User


This article refers to Yulaw's "puppet Combat", and get his guidance. Here, thank Yulaw.



As mentioned in the previous article, Puppet is used to automatically generate files that are defined on the server by the client.


We continue here to define the software that the client needs to install from the server.


Here we install httpd for example.


On the server side, we need to define the module, we define a httpd module, the name is called httpd.


The directory structure is as follows:

puppet/|-- auth.conf|-- environments|    '-- example_env|        |-- readme.environment|       |-- manifests|         '-- modules|-- fileserver.conf|-- manifests|    |-- nodes|   |    '-- cahou.linux.net.pp|    '-- site.pp|-- modules|   |-- httpd|   |   |--  files|   |   |-- mainfests|   |   |     '-- init.pp|   |    '-- templates|    ' -- test|       |-- files|        |-- manifests|       |    '-- init.pp|         '-- templates|            '-- test.erb ' -- puppet.conf15 directories, 9 files


We do this to build the directory and the required configuration files:


Take a look at the interactive process between the puppet client and the server:

    1. Puppet client sends node name and facts information to master

    2. Puppet Server Master by classifying who is requesting the client, what does it do? This decision relies on the completion of the NODE.PP configuration file contained in the SITE.PP

    3. The puppet server compiles the class information that the client learns into the catalog and sends it to the client

    4. The client validates and executes the catalog

    5. The client returns the execution result to master via the API


Site.pp This file is a guide to where to find and load all host-related configurations.

This file is placed by default in/etc/puppet/mainfests, where we define some global variables.


In Site.pp, you can refer to other module-defined *.pp files to make the file structure appear clear.


The configuration information that needs to be provided to the client can be arbitrarily defined, as long as the corresponding configuration file is site.pp inside the import.

The directory structure configuration we are using is:

/etc/puppet/manifests/nodes

/etc/puppet/modules

#下面我们建立了一个叫做test的模块和叫做cahou. linux.net node Mkdir-p/etc/puppet/manifests/nodesmkdir-p/etc/puppet/modules/test/{ Mainfests,templates,files}vi/etc/puppet/modules/test/manifests/init.ppclass test{File {"/tmp/$hostname. txt": cont ent = "Hello,world 1234567890!\n"; }} #在上面的模块中配置了一个变量, called $hostname, this variable needs to be passed to the Erb file, which is placed in the Templates directory under the test class, with the file name consistent with the class name. Cat/etc/puppet/modules/test/templatest/test.erb hostname <% FQDN%>


In the above steps, we have created the module test, and now we need to create the test node

Cat/etc/puppet/manifests/nodes/cahou.linux.net.ppnode ' cahou.linux.net ' {include test}


In this connection, the node information and module information have been created.


As I said earlier, puppet will read the SITE.PP first, we need to let site.pp can import the node information and module information

Vi/etc/puppet/manifests/site.ppcat SITE.PP Package {Provider = "Yum"}node default {file {"/tmp/puppettest1.txt": C ontent = "Hello,first puppet test1234567890!\n";} Import "/etc/puppet/modules/httpd/mainfests/init.pp" import "/etc/puppet/manifests/nodes/*.pp"


At this point, the client can fetch the information to the server, and we can take a mock execution so that we can see if it can be executed (but not really).

Puppet agent--server cahoa.linux.net--test--verbose--no-daemonize--noopinfo:retrieving Pluginfactsinfo:retrievin G plugininfo:caching Catalog for Cahou.linux.netWarning:The package type ' s allow_virtual parameter would be changing its Default value from False to true in a future release.   If you don't want to allow virtual packages, please explicitly set Allow_virtual to False. (at/usr/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in ' default ') Info:applying configuration Version ' 1413640549 ' notice:finished catalog run in 0.38 seconds


Above the warning information, we ignore, we can see that the configuration information has been taken.


Below we give it a function, let the server to the client install httpd.


To do this, we'll add a module,


Mkdir-p/etc/puppet/modules/httpd/{mainfests,templates,files}


Edit the httpd module file and specify the Yum source inside

cat /etc/puppet/modules/httpd/mainfests/init.pp class httpd {yumrepo               {  "Reposohu":                      descr     =>   "Sohu repo",                      baseurl  =>    "http://mirrors.sohu.com/centos/5.11/os/i386/",                      gpgcheck =>   "0",                       enabled  =>   "1";              }     package               {                      "httpd":                      ensure  =>   installed,                       require =>   yumrepo["Reposohu"];               }}


To modify the node information, add a reference httpd module:

CAT/ETC/PUPPET/MANIFESTS/NODES/CAHOU.LINUX.NET.PP node ' cahou.linux.net ' {include test include httpd}


At this point, the client can install HTTPD by synchronizing the information to the server.

[[email protected] ~]# puppet agent  --server cahoa.linux.net  -- test --no-daemonizeinfo: retrieving pluginfactsinfo: retrieving plugininfo:  Caching catalog for cahou.linux.netwarning: the package type ' S allow_ Virtual parameter will be changing its default value from false  to true in a future release. If you do not want  To allow virtual packages, please explicitly set allow_virtual to  false.    (at /usr/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in  ' default ') info: applying configuration version  ' 1413640549 ' notice: /stage[main]/httpd/package [Httpd]/ensure: creatednotice: finished catalog run in 61.91 seconds[[email  protected] ~]# rpm -q httpd[[email protected] ~]# ll -c  /etc/httpd/conf/ httpd.conf -rw-r--r-- 1 root root 33726 oct 18 23:54 /etc/httpd/ conf/httpd.conf# from the above httpd.conf ctime information, we can see that this is just the httpd installed.

This article is from the Linux and networking blogs, so be sure to keep this source http://khaozi.blog.51cto.com/952782/1565561

Use Puppet to automatically install httpd to clients

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.