Wednesday, October 24, 2018

Puppet Quick Start

Puppet Quick Start



Puppet plan:
=======================

1.Installing Puppet Enterprise Server & Nodes

2.Creating Manifest File
3.Configuring the Facts,Varaibles & Control Statements in Manifest File
4.Deploying EC2 Resources With Puppet

Installing Puppet Enterprise Server & Nodes:

Step 1: Create Puppet Master & Puppet Node in Server Lab Control Center
 -> Goto Server Lab Control Center->Distribution
-> Choose the Puppet Enterpise 2016->Start the Server
-> After Creating the Servers it displays user,passwd details at the end of Page
-> Copy the Public Hostname
Step 2: Login to Server in CLI using Public Hostname
1
 ssh username@PublicHostname
Step 3: Configure the /etc/hosts with your IP Address & Hostname in Puppet Master & Puppet Node
1
  vi /etc/hosts
Step 4: Run the Puppet installer Command
1
  cd /root/puppet-enterprise-2016.2.1-el-7-x86_64
1
  ./puppet-enterprise-installer
Choose the Guided install
Step 5: Access the Puppet in the Console
https://SERVERIP:3000
->Let’s Get Started->Select Monolithic
->Select Install on this Server->Select Puppet Master FQDN
->Enable Application Orchestration->Install PostgresSQL on Puppet Server
->Enter Console Admin passwd then Submit->Continue->Validating the installation
->Deploy Now->Click on Start using Puppet Enterprise->Login with username & Passwd
Step 6: Copy the Unsigned Cerificates for Installing the node
            Login to Puppet Enterprise Console->Go to Nodes tab
->Select Unsigned Certificates->Copy the Url
Step 7: Install the Node in CLI
            Login to Node->Paste the Unsigned Certificate Url
Step 8: Check the Node is added or not in the Puppet Enterprise Console
Goto Nodes->Select Inventory->Then we see the Node Details
Goto Nodes->Unsigned Certificates->Accept the Node DNS Certificate
Step 9: Apply the catalog in CLI of Agent
1
puppet agent -t

Puppet Manifests:Resources,Attributes & Parameters

Step 1: Generate a Password using the openssl
          
1
openssl  passwd  -1
Copy the generated passwd & Paste in site.pp
Step 2: Create manifests
           
1
cd  /etc/puppetlabs/code/environments/production/manifests
1
 vi site.pp
Add the Code
    node default {

# ensures server has user/pass credentials on all nodes

user { ‘resource type’ :
name                  => ‘username’,
groups               => ‘groupname’,
managehome     =>  true,
password          => ‘passwd generated by openssl’ ,
ensure              => present
}
}
Step 3: Validate the Puppet Code of Manifest File
           
1
puppet parser validate  site.pp
Step 4: Compile the Puppet Code of Manifest File
1
 puppet apply   - -noop site.pp 
           #With no changes made
1
 puppet apply  site.pp    
                       #Without no Changes made
Step 5: Check the individual status of Nodes in Puppet Enterprise Console
Configuration -> Overview -> Enforcement
We will see detailed info of nodes are successful & no changes like
            0 with failed changes
            1 with successful changes
            2 with no changes
Step 6: Check the reports of the Nodes in Puppet Enterprise Console   
Configuration ->  Reports -> Log -> See the Logs of Node actually Puppet made the changes

Facts, Variables & Control Statements

Step 1: Create module directory
           
1
cd /etc/puppetlabs/code/environments/production
1
 mkdir motd
Under this directory Create a directories examples,facts.d,files,lib,manifests,spec,
     templates   
 Step 2: Create Manifest file under the motd directory
1
cd motd/manifests
1
vi init.pp
#Add the Code
            class motd {
File { ‘/etc/motd’:
path           => ‘/etc/motd’,
ensure        => file,
source        =>  ‘puppet://modules/motd/motd’,
}
}
Step 3: Check the domain details & code  using the fact
1
facter  | grep -A  5  -B  5 domain
Select domain name from Networking attribute
Step 4: Add the Facts code,Control Statements & Variables in the Manifest file for Puppet Master & Puppet Node
1
vi init.pp
#Add the Code
            class motd {
$hostname       =  $facts[‘networking’][‘fqdn’]
$os_name         = $facts[‘os’][‘name’]
$os_release        = $facts[‘os’][‘release’]
if  $hostname = = ‘hostname of server’ {
File { ‘/etc/motd’:
path       => ‘/etc/motd’,
ensure    => file,
source    =>  ‘puppet://modules/motd/motd’,
content  => “\n\n[Puppet Master] ${hostname} ${os_name} ${os_release}\n\n”,
}
}
elseif  $hostname = = ‘hostname of server’ {
File { ‘/etc/motd’:
path       => ‘/etc/motd’,
ensure    => file,
source    =>  ‘puppet://modules/motd/motd’,
content  => “\n\n[Puppet Master] ${hostname} ${os_name} ${os_release}\n\n”,
}
}
}
Step 5: Validate the Puppet Code of Manifest File
           
1
puppet parser validate  init.pp
Step 6: Compile the Puppet Code of Manifest File
1
 puppet apply   - -noop init.pp 
1
  puppet apply  init.pp  
Step 7: Check the motd file
1
cat /etc/motd
Step 8: Login one of the Puppet

Deploying EC2 Resources With Puppet

  • SET UP
  • Development
  • Deploying the Instances
  • Terminating the Instances
  • Check in the AWS Console the instances is Shutting down

SET UP:

Step 1: Check the Puppet Agent locally Installed on your Machine
           
1
which puppet
Step 2: Verify The Version of Puppet
1
puppet   -V
Step 3: Install the Install aws-sdk-core
1
  sudo /opt/puppetlabs/puppet/bin/gem install aws-sdk-core retries
Step 4: Install Puppetlabs-aws Module
1
 /opt/puppetlabs/bin/puppet module install puppetlabs-aws
Step 5: Verify Configured Path
puppet config print modulepath
It will return the Currently Configured Module Path
1
 /Users/rilindo/.puppetlabs/etc/code/modules:/opt/puppetlabs/puppet/modules
Step 6: Export the AWS Credentials in your Shell
1
   export AWS_ACCESS_KEY_ID=your_access_key_id
1
      export AWS_SECRET_ACCESS_KEY=your_secret_access_key
Step 7: Check the AWS Credentials file
1
  cat ~/.aws/credentials
This data is present in the Credentials file
[default]
1
 aws_access_key_id = your_access_key_id
1
aws_secret_access_key = your_secret_access_key
Step 8: Finallly Verify the Setup By running the Puppet Resource
puppet resource ec2_instance

Development:

Step 1: Create a directory  src/puppet/modules
1
  mkdir –p src/puppet/modules
1
     cd src/puppet/modules/
1
 mkdir aws_demo
Step 2: Under aws_demo directory ,Create a .pp file
1
  vi aws_demo/create.pp
 in that vi editor Insert Puppet Code
ec2_instance { 'myinstancename':
ensure              => present,
region              => 'us-west-1',
image_id            => 'ami-48db9d28',
instance_type       => 't2.micro',
security_groups     => ['Access'],
subnet              => 'Public',
}
Step 3: Run the Puppet Parser to Validate the file
1
puppet parser validate aws_demo/create.pp

Deploying the Instance:

Step 1: Run the Puppet apply to .pp file
1
 puppet apply aws_demo/create.pp
->  Login to your AWS Web console and go to EC2, the Instances
->  You will see your instance being created in the AWS

Terminating the Instances:

Step 1: Copy the fiel create.pp to destroy.pp file
1
cp aws_demo/create.pp aws_demo/destroy.pp
1
sudo vi aws_demo/destroy.pp
Makes some changes in Puppet code
ec2_instance { ‘myinstancename’:
ensure        => absent,
region        => ‘us-west-1’,
image_id      => ‘ami-48db9d28’,
instance_type=> ‘t2.micro’,
security_groups     => [‘Access’],
subnet              => ‘Public’,
}
Step 2: Validate the destroy.pp file using Puppet parser
1
   puppet parser validate aws_demo/destroy.pp
Step 3: Run the destroy.pp file
1
  puppet apply aws_demo/destroy.pp

Check in the AWS Console the instances is Shutting down

Setup with Hiera:
Step 1: Create a directory hierdata under ~/src/puppet
1
   mkdir hieradata
Step 2: Create a yaml file
1
  vi hieradata/common.yaml
Insert the Following Attributes
---
ami: ami-48db9d28
region: us-west-1
Step 3: Create a hiera.yml file under /src/puppet directory
             :hierarchy:
           - common
             :backends:
          - yaml
           :yaml:
           :datadir: 'hieradata'
Step4:Copy modules/aws_demo/create.pp to modules/aws_demo/create_with_hiera.pp
1
Vi modules/aws_demo/create_with_hiera.pp
         ec2_instance { 'myinstancename_withhiera':
         ensure              => present,
         region              => hiera('region'),
         image_id            => hiera('ami'),
         instance_type       => 't2.micro',
         security_groups     => ['Access'],
         subnet              => 'Public',
}
 Step 5: Validating the Code
1
 puppet parser validate modules/aws_demo/create_with_hiera.pp
Step 6: Execute the code      
1
puppet apply modules/aws_demo/create_with_hiera.pp --hiera_config hiera.yaml
->Log into AWS Console Then Verify the Instances

No comments:

Post a Comment