Ask Your Question
1

Making sure package is installed after puppet apply

asked 2014-08-01 13:10:03 -0500

puppit gravatar image

I've written a puppet class for installing Openresty 1.5.8.1 on Debian 7, I've first compiled Openresty from source into a .deb package and then used "package" resource for installing it. The class is as follows:

class openresty {

#Update package lists
exec { "apt-update":
  command => "/usr/bin/apt-get update",
  }

#Upgrade packages
exec { "apt-upgrade":
  command => "/usr/bin/apt-get upgrade -y",
  require => Exec["apt-update"],
  }

#Stop apache
service { 'apache2':
  ensure => stopped,
  enable     => false,
  hasstatus  => true,
}

#Remove apache
package { 'apache2':
  ensure => "purged",
  require => Service["apache2"],
}


#Install pre-requisites

$prerequisites = [ "gcc", "g++", "libreadline-dev", "libncurses5-dev", "libpcre3-dev", "libssl-dev", "perl", "make", "libpcre3", "libssl-dev", "libc6-dev", "automake", "autoconf", "gdebi" ]

package { $prerequisites: 
  ensure => 'installed',
  require => Exec["apt-upgrade"],
  }

#Copy openresty.deb
file { "openresty-deb":
  ensure => "present",
  mode => '0644',
  owner => 'root',
  group => 'root',
  source => "puppet:///root/openresty_1.5.8.1-1_amd64.deb",
  }
package {'openresty': 
  ensure    => installed,
  provider  => gdebi,
  require => File["openresty-deb"],
}

}

I've tested this on Xubuntu 14.04, When I run the above manifest, I get:

Notice: Compiled catalog for xubuntu-14 in environment production in 0.04 seconds
Notice: Finished catalog run in 0.08 seconds

I'm assuming going by the above output that the package was installed successfully. My question is, there a way where I can be sure that the packages mentioned in the manifest were really installed and view any warnings that may have been generated. Also as I'm new to puppet can someone give me pointers on improving the above class?

Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-08-01 21:15:46 -0500

lavaman gravatar image

updated 2014-08-01 21:19:31 -0500

It's likely that puppet did nothing to the node. Did you actually include that class via nodes.pp or an enc? Puppet always lets you know it did something. If the package wasn't installed before the run, you would certainly see output of puppet at least trying to install it.

Also, you really want to add your deb to a proper apt repository and not try to copy the deb down to the local machine.

I don't see gdebi in the standard list of package providers, so either you're getting that from another module somehow or your code above doesn't even compile.

In more general terms, you almost certainly don't want to be running an upgrade every single puppet run. That could easily lead to some things breaking.

You should create an apt module and put the apt-related things in there. To ensure that apt-get update runs before any packages are installed, you can add something like the following to your site.pp:

Exec['apt-update'] -> Package <| |>

The arrow is chaining syntax and the thing on the right is the "spaceship operator" aka a resource collector. This will ensure that apt-get update runs before any package resources anywhere (not just in this class) are applied.

You should have a separate module for apache with a disabled subclass that you can include.

You should put your pre-reqs into a build-tools module and include that.

All static strings should always be in single quotes. The parser looks inside double-quoted strings for variable interpolation ( "The value of foo is: ${foo}" ). This affects catalog compilation time with larger manifests.

edit flag offensive delete link more
0

answered 2014-08-04 12:46:25 -0500

puppit gravatar image

Thanks for answering, I've been working on this and have developed a new manifest. I have tested this Xubuntu 14.04 and it works just fine. One change I've made is that now one can provide the download URL of the version to be installed in a file and the manifest will read from that file and install that version, not the perfect way but it'll do for the time being.

     class openresty {
        include openresty::prerequisites, openresty::install, openresty::service
    }
    #Requires a txt file containing the URL from where the openresty.tar.gz will be downloaded

     #Declare variables
     $destination_dir = '/var/tmp/openresty'
     $extract_command = 'tar -zxvf'
     $version = '/tmp/version'       #Provide the download URL in this file

    Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }

 class openresty::prerequisites{    

     #Update package lists
     exec { "apt update":
      command => "apt-get update",
     }

     #Stop apache
     service { 'apache2':
      ensure => stopped,
      enable     => false,
      hasstatus  => true,
     }

     #Install pre-requisites
     $prerequisites = [ "gcc", "g++", "libreadline-dev", "libncurses5-dev", "libpcre3-dev", "perl", "make", "libpcre3", "libssl-dev", "libc6-dev", "automake", "autoconf", "wget", "php5-fpm", "git" ]

     package { $prerequisites: 
      ensure => 'installed',
      require => Exec["apt update"],
     }
    }

class openresty::install {

     #Removes any previous instance of $destination_dir where we'll untar
     exec { "del previous":
      cwd  => '/var/tmp',
      command => "rm -rf $destination_dir; mkdir -p $destination_dir ",
      require =>  [Package [$prerequisites],
                   Exec ["wget openresty"]
        ],   
     }

     exec { 'wget openresty':
      command => "cat $version | xargs wget",
      cwd => '/tmp',
     }


     #Untar 
     exec { "untar openresty":
      cwd => '/tmp',
      command => "$extract_command $(grep -o ngx_.* /tmp/version) -C $destination_dir",
      require =>  [Package [$prerequisites], 
                   Exec["wget openresty"]
        ],
     }

     #Configure the package with required parameters and install
     exec { "install openresty":
      cwd     => '/var/tmp/openresty',
      command => "cd ngx_*; ./configure --prefix=/usr/local/openresty --sbin-path=/usr/local/sbin/nginx --pid-path=/run/nginx.pid --with-luajit --with-pcre-jit  --with-pcre --with-http_ssl_module --without-http_memcached_module --without-http_redis2_module --without-http_redis_module --without-http_memc_module ; make ; make install",
      creates => '/usr/local/openresty',
      provider => 'shell',
      require =>  [Package [$prerequisites], 
                   Exec ["untar openresty"],
                   Exec ["wget openresty"],
        ],
      }

    }

class openresty::service {

     #Get init script
     exec { "get nginx init script":
      cwd => '/tmp',
     command => "git clone https://github.com/Fleshgrinder/nginx-sysvinit-script.git ; cp nginx-sysvinit-script/nginx /etc/init.d/nginx ; chmod 0755 /etc/init.d/nginx ; chown root:root /etc/init.d/nginx" ,
     require => [Package [$prerequisites], 
                  Exec ["untar openresty"], 
                  Exec ["install openresty"]
        ],
     }

     #Start the Nginx service
     service { 'nginx':
     ensure => 'running',
     enable => 'true',
     hasstatus  => 'true',
     provider => 'debian',
     require => [Package [$prerequisites], 
                  Exec ["untar openresty"], 
                  Exec ["install openresty"],
                  Exec ["get nginx init script"]
        ],
     }
}

Class ["openresty::prerequisites"] -> Class ["openresty::install"] -> Class ["openresty::service"]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-08-01 13:10:03 -0500

Seen: 1,490 times

Last updated: Aug 04 '14