{"id":288,"date":"2015-12-10T11:49:02","date_gmt":"2015-12-10T11:49:02","guid":{"rendered":"http:\/\/www.howtolearnlinux.com\/?p=288"},"modified":"2018-05-01T11:56:13","modified_gmt":"2018-05-01T11:56:13","slug":"puppet-installation-and-basic-configuration","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=288","title":{"rendered":"Puppet : Introduction, Installation and basic configuration"},"content":{"rendered":"<p>Puppet is a configuration Management tool, used for managing configuration of systems systematically. It keeps a historical record of state of systems properly.\u00a0 Puppet used pull methodology where nodes request configuration details from a server. It works on a Master and Slave environment. It\u00a0helps system administrators automate the provisioning, configuration, and management of a server infrastructure<\/p>\n<p>The architecture\u00a0used is where the client\/slave node contacts the server\/Master node and supplies few information about the client. The server verifies the records, creates a catalog, a document that tells the desired configuration of that client node, and updates the client node about the configurations to be used. Then the client updates the server with the status of configuration.<\/p>\n<p><strong>Installing puppet master server<\/strong><\/p>\n<ul>\n<li>Install CentOS 7<\/li>\n<li>Update all packages using the command &#8220;<em>yum update<\/em>&#8221;<br \/>\nInstall vmware tools if the host is a vm running on ESX<\/li>\n<li>Ensure the hostname is correct in the file &#8220;<em>\/etc\/hostname<\/em>&#8221;<br \/>\n#] <strong><em>rpm -ivh http:\/\/yum.puppetlabs.com\/puppetlabs-release-el-7.noarch.rpm<\/em><\/strong><br \/>\n#] <strong><em>yum install puppet-server<\/em><\/strong><\/li>\n<li>Edit the file &#8220;<em>\/etc\/puppet\/puppet.conf<\/em>&#8220;. In the<em> [main]<\/em> section add the following line<br \/>\n<em>dns_alt_names = &lt;hostname&gt;,&lt;FQDN of hostname&gt;<\/em><\/li>\n<li>Ensure the host can ping the client using the <strong>hostname<\/strong><\/li>\n<li>Start the service by using the command<br \/>\n#] <em><strong>systemctl start puppetmaster<\/strong><\/em><\/li>\n<li>The command &#8220;<strong>puppet help<\/strong>&#8221; will give information including the revision of puppet application installed.<\/li>\n<\/ul>\n<p><strong>Installing puppet agents in client hosts<\/strong><\/p>\n<ul>\n<li>Install CentOS 7<\/li>\n<li>Update all packages using the command &#8220;<em>yum update<\/em>&#8220;<\/li>\n<li>Install vmware tools if the host is a vm running on ESX<\/li>\n<li>Ensure the hostname is correct in the file &#8220;<em>\/etc\/hostname<\/em>&#8221;<br \/>\n#] <strong><em>echo &#8220;&lt;IP of pupper master server&gt;\u00a0 &lt;hostname of pupper master server&gt;\u00a0\u00a0 &lt;FDQN hostname of pupper master server&gt;&#8221; &gt;&gt; \/etc\/hosts<\/em><\/strong><\/li>\n<li>#] <strong><em>rpm -ivh http:\/\/yum.puppetlabs.com\/puppetlabs-release-el-7.noarch.rpm<\/em><\/strong><\/li>\n<li>#] <strong><em>yum install puppet -y<\/em><\/strong><\/li>\n<li>Ensure the host can ping the server using the\u00a0<strong>hostname<\/strong><\/li>\n<li>Add the following line in the file &#8220;<em>\/etc\/puppet\/puppet.conf<\/em>&#8220;:<br \/>\n<em>server=&lt;<strong>hostname<\/strong> of pupper master server&gt;<\/em><\/li>\n<\/ul>\n<p><strong>Starting the services:<\/strong><\/p>\n<ul>\n<li>Ensure the firewall is stopped in both the tests hosts, and SELinux is disabled. Puppet server uses &#8220;<strong>tcp port 8140<\/strong>&#8221; for connections.<\/li>\n<li>Issue the command &#8220;<strong><em>systemctl start puppetmaster<\/em><\/strong>&#8221; in the puppet master host<\/li>\n<li>Puppet uses <em>SSL certificates<\/em> to authenticate communication between master and agent systems.<\/li>\n<li>After a minute issue the command &#8220;<strong><em>puppet agent &#8211;no-daemonize &#8211;onetime &#8211;verbose<\/em><\/strong>&#8221; in the puppet client host<\/li>\n<li>You may see an error message that says &#8220;<em><strong>Exiting; no certificate found and waitforcert is disabled<\/strong><\/em>&#8220;. This is normal. Proceed with the following step to accept the certificate in the server.<\/li>\n<li>Check the logs in &#8220;<em>\/var\/log\/messages<\/em>&#8221; in the client host to see if the client was able to start without any issue<\/li>\n<li>In the server host issue the command &#8220;<strong><em>puppet cert list<\/em><\/strong>&#8221; to see if there is an entry from the client host. This will be the certificate from the client, requesting it to the signed.<\/li>\n<li>Issue the command &#8220;<strong><em>puppet cert sign &lt;client hostname&gt;<\/em><\/strong>&#8220;. Now our client &lt;client hostname&gt; is authorized to fetch and apply configurations from the puppet server.<\/li>\n<li>(The command &#8220;<em><strong>puppet cert clean &lt;hostname&gt;<\/strong><\/em>&#8221; is used to remove the certificate)<\/li>\n<\/ul>\n<p>The command &#8220;<em><strong>puppet agent &#8211;test<\/strong><\/em>&#8221; when executed on a puppet client will communicate with the server\u00a0and apply the main manifest.<\/p>\n<p><strong>Configuring puppet server to create a file named <\/strong><em>\/usr\/local\/sbin\/puppetsimple.sh<\/em><em>\u00a0<\/em><strong>and install<\/strong><em><strong>\u00a0<\/strong>apache webserver\u00a0<\/em><strong>in the client<\/strong><\/p>\n<ul>\n<li>In the puppet master host create the file &#8220;<em>\/etc\/puppet\/manifests\/site.pp<\/em>&#8221; with the following content:<\/li>\n<li><\/li>\n<\/ul>\n<p><em>class toolbox {<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0file {&#8216;\/usr\/local\/sbin\/puppetsimple.sh&#8217;:<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0owner =&gt; root, group =&gt; root, mode =&gt; 0755,<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0content =&gt; &#8220;#!\/bin\/sh \\necho &#8216;HHHHEEEELLLLOOO&#8217; $1\\n&#8221;,<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0}<\/em><\/p>\n<p><em>class apache {<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 package {&#8216;httpd&#8217;:<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ensure =&gt; installed,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/em><br \/>\n<em>}<\/em><br \/>\n<em>}<\/em><em>node &#8216;&lt;client hostname&gt;&#8217;\u00a0\u00a0 \u00a0{<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0include toolbox<\/em><\/p>\n<p><em>include apache<\/em><br \/>\n<em>}<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Puppet master gathers facts about its nodes with a tool called <em><strong>facter<\/strong><\/em>, which by default, gathers information such as OS, hostnames, IP addresses, SSH keys, etc. This info the server gets from the client node can in-turn be used to configure parameters such as IP, hostname, etc in the configurations for the client.<\/p>\n<p>The puppet agent when connects and checks with the puppet master, it will send facts about itself to the master, and pull a current catalog (a compiled list of resources and their desired states that are relevant to the agent, determined by the main manifest). Then the agent node will attempt to make the appropriate changes to achieve its desired state.<\/p>\n<p>Puppet programs are called manifests, composed of puppet code,\u00a0written in a &#8220;<em><strong>.pp<\/strong><\/em>&#8221; file. The default main manifest is <em><strong>site.pp<\/strong><\/em><\/p>\n<p><strong>Retrieving new instructions from the puppet master that will create the file<\/strong><\/p>\n<ul>\n<li>Issue the following command in the client host:<br \/>\n#] <em><strong>puppet agent &#8211;no-daemonize &#8211;onetime &#8211;verbose<\/strong><\/em><\/li>\n<li>#] <em><strong>ls -l \/usr\/local\/sbin\/puppetsimple.sh<\/strong><\/em><\/li>\n<li>#] <em><strong>puppetsimple.sh<\/strong><\/em><\/li>\n<li>#]\u00a0<em><strong>service httpd start<\/strong><\/em><\/li>\n<li>#]\u00a0<em><strong>service httpd status<\/strong><\/em><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Defining class to add a user named shijuv<\/strong><\/p>\n<p><em>class addmyuser{<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 user {&#8216;shijuv&#8217;:<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ensure\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; &#8216;present&#8217;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/em><br \/>\n<em>}<\/em><\/p>\n<p><strong>Defining class to delete a user<\/strong><br \/>\n<em>class delmyuser{<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 user {&#8216;shijuv&#8217;:<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ensure\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; &#8216;absent&#8217;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/em><br \/>\n<em>}<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Transferring files from the Puppet File Server<\/strong><\/p>\n<ul>\n<li>The puppet master service includes a file server that can be used for transferring files to its clients. If a file resource declaration contains a puppet: URI in its source attribute, clients will receive those files from the master\u2019s file server.<\/li>\n<li>Create a repository to store a sample file<br \/>\n#] <strong><em>mkdir -p \/etc\/puppet\/modules\/shiju_module\/files<\/em><\/strong><\/li>\n<li>Create a file for testing:<br \/>\n#] <strong><em>echo &#8220;Hello World&#8221; &gt;&gt; \/etc\/puppet\/modules\/shiju_module<\/em><\/strong><em>\/<\/em><em>files<\/em><em>\/<\/em><strong><em>shiju.txt <\/em><\/strong><\/li>\n<li>Define a class &#8220;\/etc\/puppet\/manifests\/classes\/copyfile.pp&#8221; as demonstration in above sections, with the following contents:<\/li>\n<li><\/li>\n<\/ul>\n<p><em>file { &#8220;\/tmp\/sample.txt&#8221;:<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 mode\u00a0\u00a0 =&gt; 440,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 owner\u00a0 =&gt; root,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 group\u00a0 =&gt; root,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 source =&gt; &#8220;puppet:\/\/\/modules\/shiju_module\/shiju.txt&#8221;\u00a0 <\/em><\/p>\n<p><em>\u00a0 \u00a0 #NOTE: The folder named files is deliberately removed from source parameter<\/em><br \/>\n<em>}<\/em><\/p>\n<ul>\n<li>Include the class in the &#8220;<strong><em>\/etc\/puppet\/manifests\/site.pp<\/em><\/strong>&#8221; file under the section for the client<\/li>\n<li>Run the puppet agent in the client host to retrieve information from the puppet master<\/li>\n<li>Verify if the file &#8220;<strong>shiju.txt<\/strong>&#8221; is copied to the &#8220;<strong>\/tmp<\/strong>&#8221; folder in the client<\/li>\n<\/ul>\n<p><em>Puppet automatically serves PLUGINS and FILES FROM MODULES: anything in &lt;module name&gt;\/files\/&lt;file name&gt; is available to authenticated nodes at puppet:\/\/\/modules\/&lt;module name&gt;\/&lt;file name&gt;. You do not need to edit this file to enable this.<\/em><\/p>\n<p>Default configuration for nodes not defined specifically:<\/p>\n<p>When a client node contacts the puppet server, if there are no xxxx for the node, the node will apply all condifuration defines in &#8220;<em><strong>node default {}<\/strong><\/em>&#8221; in\u00a0<strong><em>\/etc\/puppet\/manifests\/site.pp<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Puppet is a configuration Management tool, used for managing configuration of systems systematically. It keeps a historical record of state of systems properly.\u00a0 Puppet used <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=288\" title=\"Puppet : Introduction, Installation and basic configuration\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":290,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,21,3],"tags":[],"class_list":["post-288","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-configuration-management","category-devops","category-linux"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288"}],"version-history":[{"count":32,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":580,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions\/580"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/290"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}