Monday 21 December 2015

Tweaks to make puppet passenger working



I have been writing a puppet script to create VMs with ruby, rails and passenger recently and encountered quite a few small but annoying problems. Just want to write it down since it may help others.

Environments:
    Ubuntu 14
    Ruby 2.1.7
    Rails 4.2.5
    Passenger 5.0.22
    Puppet 3.4.3

Puppet modules:
    puppetlabs-concat
    puppetlabs-apache
    puppetlabs-passenger
    puppetlabs-apt
    puppetlabs-vcsrepo

1. Problem with puppetlabs/ruby v0.4.0
This module does not support Ruby version 2.2.x, so have to use Ruby '2.1.0'.

2. Problems with puppetlabs/passenger v0.4.1
2.1) Passenger version: to specify the version of passenger, according to the documentation and the example in the README, only passenger_version needs to be set. However, it is NOT working at all. Both passenger_version and package_ensure need to be set, e.g.

class {'passenger':
passenger_version      => "$passenger_version", 
package_ensure          => "$passenger_version", 
passenger_provider     => 'gem',
......
  }  
2.2) RailsAutoDetect: Passenger module adds INVALID 'RailsAutoDetect' into /etc/apache2/mods-enabled/passenger.conf. To fix it:
  file_line { 'Change RailsAutoDetect to PassengerEnabled':
 path => '/etc/apache2/mods-enabled/passenger.conf',  
 line => '        PassengerEnabled On',
 match   => "RailsAutoDetect",
 ......
  }
Update: the puppet passenger module master branch has fixed this bug but has not published to forge as of Jan 2016.


2.3) HTTP 403 error on apps: Passenger module adds 'PassengerHighPerformance On' into /etc/apache2/mods-enabled/passenger.conf. It gives an HTTP 403 error to webapps sitting on a sub path. To fix it:
  file_line { 'Disable PassengerHighPerformance':
 path => '/etc/apache2/mods-enabled/passenger.conf',  
 line => '        PassengerHighPerformance off',
 match   => "PassengerHighPerformance",
 ......
  }
Update: a better choice is to set PassengerHighPerformance off in the <Location xxx> directive.

2.4) Permissions: as the webapp will be running under apache user, you may want to add read permission to 'www-data' group to your webapp path.

3. Copy file from host to VM
Remember to remove carriage returns, for instance:
  file { 'post_config.sh':
    ensure => 'file',
source => "puppet:///modules/my_module/post_config.sh",
path   => '/app_path/post_config.sh',
        ,,,,,,
before  => Exec['Remove_carriage_returns'],
  }
  
  exec { 'Remove_carriage_returns':
    command  => "/bin/sed -i s/\r//g /app_path/post_config.sh",
require  => File['/app_path/post_config.sh'],
  }

4. Cannot create user with password
If you want to use 'user' to create a user with password, by default it WONT work, e.g. the password in /etc/shadow will be EMPTY!
  user { 'user1' :
    ensure   =>  'present',
password =>  'SHA512_PASSWORD'
shell       =>  '/bin/bash',
home     =>  '/home/user1',
managehome => true,
  }
The reason is that a ruby gem 'ruby-shadow' must be installed first! (Thanks to puppet cookbook)
package { 'ruby-shadow':
    ensure   => 'present',
    provider => 'gem',
}



































No comments:

Post a Comment