I'm enthusiastic and passionate about web development and design in all it's forms and love to build application with efficient and simple methods

Wednesday, July 1, 2015

Vagrant Rails Puppet

1:02 AM Posted by Codeinterpreter No comments
Vagrant & Puppet to easily provision virtual machines that can be used as isolated development environments for your projects. You'll keep your development machine fast, your environments isolated, and any developer will be able to get up and running on a new project in less than 5 minutes.

Puppet automates server provisioning by formalizing a server’s configuration into manifests. Puppet’s manifests are text files that contain declarations written in Puppet’s domain-specific language (DSL). When we’ve defined our configuration using this DSL, Puppet will ensure that the machine’s files, packages, and services match the settings we’ve specified


Configuration


// Initialize vagrant
vagrant up

// Enter Vagrant SSH
vagrant ssh
// Built Git repository for manifest. built it if not exist
ls -l /etc/puppet/.git/
// First we need to create a user and group for Puppet to use
sudo useradd --comment "Puppet" --no-create-home \ --system --shell /bin/false puppet

// Installing puppet as ruby gem. This will install puppet and facter
sudo gem install puppet -v 2.7.12 --no-rdoc --no-ri

facter is the tool that Puppet uses to gather information about the system in order to populate variables and determine which parts of our.

// Run Facter
facter

// Built manifests and site.pp in /etc/puppet
cd /etc/puppet
mkdir manifests
cd manifests
sudo nano site.pp

write this configuration:
Exec {
  path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}

// Commit this change
git add .
git commit -m "Init Puppet manifests"

Puppet Configurations


puppet help apply

// Run puppet
sudo puppet apply --verbose manifests/site.pp


When developing a Puppet configuration, it’s helpful to pass the --verbose flag to Puppet so that it displays any extended information that might be available if an error happens. We’ll see output like this from puppet apply:

 info: Applying configuration version '1319427535' info: Creating state file /var/lib/puppet/state/state.yaml notice: Finished catalog run in 0.02 seconds We’ll also see a few lines of output like the following ones.

This is because the Puppet developers are still bringing the codebase up-to-date for Ruby 1.9.3; these should go away in future Puppet releases.

 Could not load confine test 'operatingsystem': cannot load such file \ --  puppet/provider/confine/operatingsystem

 We’ve successfully built a tiny Puppet repository and executed Puppet on our VM. Now we’ll build out the VM with a standard Rails application stack. That is, we’ll configure Apache, MySQL, and Passenger, and we’ll put the Rails application directory tree into place. Along the way, we’ll learn all about how Puppet helps us manage our VM’s services and configuration.

Study Case

Installing Apache  on a server

In our site.pp. add this conf:
Exec {
path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
}
package {
"apache2":
ensure => present
}
service {
"apache2":
ensure => true,
enable => true
}


This package declaration is a fine example of the Puppet DSL. There’s a type declaration, package, followed by a block delimited by curly braces. That block contains a title for the instance of the type that we’re configuring, apache2.
That title is associated with various parameters that affect how Puppet will act on the type. In this case, we’ve declared an ensure parameter that’s set to present. This declaration is our way to tell Puppet that it should ensure there is a package called apache2 installed on the system.

service apache ensure true it means setting Puppet to attempt the service if it’s not running. And enable means ensures the service will start on boot


// Apply puppet
sudo puppet apply --verbose manifests/site.pp

If there's error message: "Could not load confine test 'operatingsystem' ". That's just update issue and harmless. If affecting your process just update your RoR versions.




0 comments:

Post a Comment