CONTACT @ Skype : rajdimdung   |   call : +977 9841813550

Infrastructure Automation & configuration Management Tool Puppet

Post by :    Date : 2014-11-30 04:14:26

  • Share on Facebook

Infrastructure Automation & configuration Management Tool Puppet

~Samal Dimdung

What are the common issues in traditional environments?

- Provisioning of new nodes (servers) when needed 
- Configuration consistently among different nodes 
- Custom script are written for specific operating systems and environments 
- Managing packages and configuration across thousands of nodes 
- Managing large amount of nodes becomes expensive and unmanageable 

What is  Puppet?

- Infrastructure automation and configuration management tools 
- Enforces the defined state of the infrastructure 
- Puppet can automate tasks on thousands of machines A.K.A nodes 
- Puppet enable infrastructure as code and DevOps 
- Puppet allow configuration consistency across nodes 
- Puppet enable quick provisioning of new machines in an environments 
- Puppet allow DevOps admins to write declarative instructions using the Puppet Language 
- Code is written inside of classes and classes are assigned to the node 
- Node classification is the process of assigning a class to a node for processing  
- Puppet was create by Luke Kanies in 2003 written in the Ruby Language  

More Advance Puppet


- Puppet is advance and there is a lot more to it such as
- Code testing (acceptance testing) tools such as beaker developed by puppet
- Puppet forge ( over 2800+ modules ready to download and use and modified as you needed, you don't have to write module from the scratch) 
- Puppet cloud provisioning
- Writing custom Puppet modules to extend puppet

How Puppet Works?

Demo:

// On client/agent:
[root@agent201 ~]# puppet agent -t 

// Do something configuration changes in master and on the client run below 

// On client/agent:
[root@agent201 ~]# puppet agent -t

// You should see some changes in client

Software Related to Puppet:

# Facter - Complementary tool to retrieve system's data 
# MCollective - Infrastructure Orchestration framework 
# Hiera - Key-value lookup tool where Puppet data can be placed 
# PuppetDB - an Inventory Service and Storage configs back end >
# Puppet DashBoard - A Puppet web front-end and External Node Classifier (ENC)
# Foreman - A well-known third party provisioning tool and Puppet ENC 
# Geppetto -  A Puppet IDE based on Eclipse 

File Management

Common Resource Types: file attributes 
Demo: 
Source, Content , Target 

[root@puppet200 modules]# pwd
/etc/puppetlabs/puppet/modules
[root@puppet200 modules]# mkdir -p filedemo/{files,manifests,tests}
[root@puppet200 modules]# ls filedemo
files  manifests  tests
[root@puppet200 modules]# vim filedemo/manifests/init.pp
[root@puppet200 modules]# cat filedemo/manifests/init.pp
class filedemo {
        file { '/root/motd':
                ensure  => present,
                content => "This is my motd file manage by content attribute\n",
                owner   => root,
                group   => root,
                mode    ==> "0644",
        }
        file {'/etc/motd':
                ensure  => link,
                target  => '/root/motd',
        }
}
[root@puppet200 modules]# cat /etc/motd
my motd text here
[root@puppet200 modules]# puppet parser validate filedemo/manifests/init.pp
[root@puppet200 modules]# vim filedemo/tests/init.pp

[root@puppet200 modules]# puppet apply filedemo/tests/init.pp
Notice: Compiled catalog for puppet200.dlab.com in environment production in 0.13 seconds
Notice: /Stage[main]/Filedemo/File[/root/motd]/ensure: created
Notice: /Stage[main]/Filedemo/File[/etc/motd]/ensure: ensure changed 'file' to ' link'
Notice: Finished catalog run in 0.25 seconds
[root@puppet200 modules]# cat /root/motd
This is my motd file manage by contenct attribute
[root@puppet200 modules]# cat /etc/motd
This is my motd file manage by contenct attribute
[root@puppet200 modules]# ls -al /etc | grep motd
lrwxrwxrwx.  1 root root     10 Nov 16 13:52 motd -> /root/motd
[root@puppet200 modules]#

Packages Management


Common Resource Types: Packages (install, uninstall, upgrade, downgrade) 

Demo: command line and both MCollecitve ( Live Management)

[root@puppet200 ~]# puppet resource package bash
package { 'bash':
  ensure => '4.1.2-15.el6_4',
}
[root@puppet200 ~]#
[root@puppet200 ~]# puppet resource package httpd
package { 'httpd':
  ensure => 'absent',
}
[root@puppet200 ~]#

package { �tree�:
	ensure => present,
}

// Installing packages with an array (multiple packages at one time)

package {[�tree�,�bind-utils�]:
	ensure => present,
}

Service Management


Common Resource Types: Services

package { �sshd�:
	ensure 	=> running,
	enable	=> true,
}

Ensure : stopped/running
Enable : determines if a service should be enable to start at boot time. Values:true/false 

More attributes can be found with puppet describe service and in the puppet labs docs

[root@agent201 ~]# puppet resource service pe-puppet ensure=stopped
Notice: /Service[pe-puppet]/ensure: ensure changed 'running' to 'stopped'
service { 'pe-puppet':
  ensure => 'stopped',
}
[root@agent201 ~]# puppet resource service pe-puppet ensure=running
Notice: /Service[pe-puppet]/ensure: ensure changed 'stopped' to 'running'
service { 'pe-puppet':
  ensure => 'running',

// Using puppet you can manage almost all the service using puppet command-line and PE console as well. PE MColletive we�ll talk this about later  

[root@agent201 ~]# puppet resource service pe-puppet ensure=stopped
Notice: /Service[pe-puppet]/ensure: ensure changed 'running' to 'stopped'
service { 'pe-puppet':
  ensure => 'stopped',
}
[root@agent201 ~]# puppet resource service pe-puppet ensure=running
Notice: /Service[pe-puppet]/ensure: ensure changed 'stopped' to 'running'
service { 'pe-puppet':
  ensure => 'running',
}
[root@agent201 ~]#

App Deployment


[root@puppet200 modules]# ls web01/
files  manifests  templates  tests
[root@puppet200 modules]# tree web01/
web01/
+-- files
+-- httpd.conf
+-- index.html
+-- manifests
+-- init.pp
+-- templates
+-- tests
    +-- init.pp

4 directories, 4 files
[root@puppet200 modules]# cat web01/manifests/init.pp
class web01 {
        package {'httpd':
                ensure => present,
                before  =>File['/etc/httpd/conf/httpd.conf'],
        }
        file {'httpd.conf':
                ensure  => file,
                path    => '/etc/httpd/conf/httpd.conf',
                mode    => 600,
                #source         => '/root/examples/httpd.conf',
                source  => 'puppet:///modules/web01/httpd.conf',
        }
        file {'/var/www/html/navigator':
                ensure => directory,
        }
        file {'/var/www/html/navigator/index.html':
                ensure => file,
                #content => "This is Web page Deployed by Puppet Master for web01\n",
                source => 'puppet:///modules/web01/index.html',
        }
        service {'httpd':
                ensure          => running,
                enable          => true,
                subscribe       => File['/etc/httpd/conf/httpd.conf'],
        }
}
[root@puppet200 modules]# cat web01/te
templates/ tests/
[root@puppet200 modules]# cat web01/tests/init.pp
include web01
[root@puppet200 modules]#

Puppet Enterprise console


Related Posts