Configuring Apache with Puppet and Vagrant - apache

I'm using Vagrant and Puppet for the first time in a project and I keep running into an issue.
I've used PuPHPet as a starting point, and I have the following snippet in my default.pp manifest:
class { 'apache': }
apache::dotconf { 'custom':
content => 'EnableSendfile Off',
}
apache::module { 'rewrite': }
apache::vhost { 'awesome.dev':
server_name => 'awesome.dev',
serveraliases => [
],
docroot => '/var/www',
port => '80',
directories => [ { path => '/var/www/', allow => 'from all', allow_override => ['All'] } ],
env_variables => [],
priority => '1',
}
When I run it, I always get the following error:
warning: Could not retrieve fact fqdn
Invalid parameter directories at /tmp/vagrant-puppet/manifests/default.pp:46 on node precise32
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
cd /tmp/vagrant-puppet/manifests && puppet apply --verbose --modulepath '/etc/puppet/modules:/tmp/vagrant-puppet/modules-0' default.pp --detailed-exitcodes || [ $? -eq 2 ]
Line 46 is the end of the apache::vhost rule. I want to set it to allow override using htaccess, but I can't see where I've gone wrong. Can anyone see what the issue is?

PuPHPet uses the Example42 Apache Puppet module, see the README file. This module doesn't have a directories parameter in the vhost resource:
https://github.com/puphpet/puphpet-apache/blob/master/manifests/vhost.pp#L100
Only the Puppet Labs Apache module has a directories parameter, but it's a different module:
https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp#L25
You can however use the directory parameter in Example42's module similarly to the example which can be found in the vhost resource:
# apache::vhost { 'my.other.site':
# docroot => '/path/to/docroot',
# directory => '/path/to',
# directory_allow_override => 'All',
# }

Related

LogStash catch my logs only with debug mod

I have a little problem on logstash. When I test in debug mode everything is OK with the command
sudo /usr/share/logstash/bin/logstash --debug --path.settings /etc/logstash -f /etc/logstash/conf.d/apache.conf
But if I start logstash in service with systemctl (systemctl start logstash), it starts but does not trap any log. Nothing happens (the logstash logs do not move ...). All commands in sudo or root.
Logstash and Apach are not on the same machine as Elasticsearch (but it works since in debug they communicate)
Do you know why ?
EDIT
This is the pipeline configuration
input {
file {
path => "/var/log/httpd/access_log"
}
}
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
mutate {
convert => {
"response" => "integer"
"bytes" => "integer"
}
}
}
output {
elasticsearch {
hosts => "192.168.1.2:9200"
index => "apache-int-%{+YYYY.MM.dd}"
}
}
And extraction of logstash log id available here : https://sharetext.me/U9RAMT
Well, I just found ... When I started debug mode, I was root, when systemctl starts logstash, it uses user logstash which does not have access to httpd logs!
With the right rights, it works better!

vagrant provisining don't work on Windows but work on Ubuntu

I have vagrant/puppet provision script and see there is a problem when my host machine is Windows (when hosting on Ubuntu doesn't seems to have this problem). I can see that apache::concat working with apache ports.conf file have a problem. I'm using guest box same on both places (ubuntu server 14.04). As far as I know puppet is running on guest machine.
My question is why I have this warnings and errors during provisioning?
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: stdin: is not a tty
==> default: Notice: Compiled catalog for eclectic.vm in environment production in 7.06 seconds
==> default: Notice: /Stage[main]/Main/Exec[apt-update]/returns: executed successfully
==> default: Notice: /Stage[main]/Main/Exec[git-checkout-drush]/returns: executed successfully
==> default: Notice: /Stage[main]/Main/File[/var/www/vhosts/eclectic.ca]/mode: mode changed '0777' to '0775'
==> default: Notice: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/File[/var/www/vhosts/eclectic.ca/public_html]/owner: owner changed 'www-data' to 'root'
==> default: Notice: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/File[/var/www/vhosts/eclectic.ca/public_html]/group: group changed 'vagrant' to 'root'
==> default: Error: /Stage[main]/Apache/Concat[/etc/apache2/ports.conf]/Exec[concat_/etc/apache2/ports.conf]: Could not evaluate: /usr/bin/env: ruby
: No such file or directory
==> default: Notice: /Stage[main]/Apache/Concat[/etc/apache2/ports.conf]/File[/etc/apache2/ports.conf]: Dependency Exec[concat_/etc/apache2/ports.conf] has failures: true
==> default: Warning: /Stage[main]/Apache/Concat[/etc/apache2/ports.conf]/File[/etc/apache2/ports.conf]: Skipping because of failed dependencies
==> default: Notice: /Stage[main]/Main/Exec[composer-install-drush]/returns: executed successfully
==> default: Error: /Stage[main]/Main/Apache::Vhost[ssl-ca.eclectic.vm]/Concat[25-ssl-ca.eclectic.vm.conf]/Exec[concat_25-ssl-ca.eclectic.vm.conf]: Could not evaluate: /usr/bin/env: ruby
: No such file or directory
==> default: Notice: /Stage[main]/Main/Apache::Vhost[ssl-ca.eclectic.vm]/Concat[25-ssl-ca.eclectic.vm.conf]/File[25-ssl-ca.eclectic.vm.conf]: Dependency Exec[concat_25-ssl-ca.eclectic.vm.conf] has failures: true
==> default: Warning: /Stage[main]/Main/Apache::Vhost[ssl-ca.eclectic.vm]/Concat[25-ssl-ca.eclectic.vm.conf]/File[25-ssl-ca.eclectic.vm.conf]: Skipping because of failed dependencies
==> default: Notice: /Stage[main]/Main/Apache::Vhost[ssl-ca.eclectic.vm]/File[25-ssl-ca.eclectic.vm.conf symlink]: Dependency Exec[concat_25-ssl-ca.eclectic.vm.conf] has failures: true
==> default: Warning: /Stage[main]/Main/Apache::Vhost[ssl-ca.eclectic.vm]/File[25-ssl-ca.eclectic.vm.conf symlink]: Skipping because of failed dependencies
==> default: Error: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/Concat[25-ca.eclectic.vm.conf]/Exec[concat_25-ca.eclectic.vm.conf]: Could not evaluate: /usr/bin/env: ruby
: No such file or directory
==> default: Notice: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/Concat[25-ca.eclectic.vm.conf]/File[25-ca.eclectic.vm.conf]: Dependency Exec[concat_25-ca.eclectic.vm.conf] has failures: true
==> default: Warning: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/Concat[25-ca.eclectic.vm.conf]/File[25-ca.eclectic.vm.conf]: Skipping because of failed dependencies
==> default: Notice: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/File[25-ca.eclectic.vm.conf symlink]: Dependency Exec[concat_25-ca.eclectic.vm.conf] has failures: true
==> default: Warning: /Stage[main]/Main/Apache::Vhost[ca.eclectic.vm]/File[25-ca.eclectic.vm.conf symlink]: Skipping because of failed dependencies
==> default: Notice: /Stage[main]/Apache::Service/Service[httpd]: Dependency Exec[concat_/etc/apache2/ports.conf] has failures: true
==> default: Notice: /Stage[main]/Apache::Service/Service[httpd]: Dependency Exec[concat_25-ca.eclectic.vm.conf] has failures: true
==> default: Notice: /Stage[main]/Apache::Service/Service[httpd]: Dependency Exec[concat_25-ssl-ca.eclectic.vm.conf] has failures: true
==> default: Warning: /Stage[main]/Apache::Service/Service[httpd]: Skipping because of failed dependencies
==> default: Notice: Finished catalog run in 18.24 seconds
My puppet file
# execute 'apt-get update'
exec { 'apt-update':
command => 'apt-get update',
path => ["/usr/bin"],
}
# Install and configure apache2
class { 'apache': # use the "apache" module
default_vhost => false, # don't use the default vhost
default_mods => false, # don't load default mods
mpm_module => 'prefork', # use the "prefork" mpm_module
service_ensure => 'running',
}
include apache::mod::php
include apache::mod::rewrite
# Enable not define apache mods
# https://forge.puppetlabs.com/puppetlabs/apache#defined-type-apachemod
apache::mod { 'access_compat': }
# http eclectic version
apache::vhost { 'com.domain.vm':
port => '80',
docadmin => '/var/www/vhosts/domain.com/public_html',
override => ['all'],
serveraliases => [
'www.com.domain.vm',
],
}
# https eclectic version
apache::vhost { 'ssl-com.domain.vm':
servername => 'com.domain.vm',
port => '443',
docadmin => '/var/www/vhosts/domain.com/public_html',
override => ['all'],
ssl => true,
serveraliases => [
'www.com.domain.vm',
],
}
# Setting up custom web eclectic direcotry
file { [
"/var/www",
"/var/www/vhosts",
"/var/www/vhosts/domain.com"
]:
ensure => "directory",
owner => "www-data",
group => "vagrant",
mode => 775,
}
# Add virtual host domain in /etc/hosts
host { 'com.domain.vm':
ensure => present,
ip => '127.0.0.1',
host_aliases => 'www.com.domain.vm',
}
# install mysql-server package
package { 'mysql-server':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# ensure mysql service is running
service { 'mysql':
ensure => running,
require => Package['mysql-server'],
}
$packages = [
'vim',
'nano',
'htop',
'tree',
'pv',
'wget',
'curl',
'git',
'php5',
'php5-cli',
'php5-gd',
'php5-curl',
'php5-mysql',
'php5-mcrypt',
]
package { $packages:
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
exec { 'set-mysql-password':
command => 'mysqladmin -u admin password "admin"',
path => ["/usr/bin"],
logoutput => true,
unless => 'mysqladmin -uadmin -padmin version',
require => Service['mysql'],
}
package { 'php-pear':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
notify => [
Exec['pear-discover-channel-phing'],
Exec['pear-install-Console_Table'],
Exec['pear-install-Console_Color2'],
]
}
# http://puppet-php.readthedocs.org/en/latest/composer.html#installation
# Install to different destination
class { 'php::composer':
destination => '/usr/bin/composer',
notify => Exec['composer-install-drush']
}
exec { "pear-discover-channel-phing":
command => "pear channel-discover pear.phing.info",
path => ["/usr/bin"],
logoutput => true,
unless => 'pear channel-info pear.phing.info',
require => Package['php-pear'],
notify => Exec['pear-install-phing'],
}
exec { "pear-install-phing":
command => "pear install phing/phing",
unless => "which phing",
path => ["/usr/bin"],
logoutput => false,
require => Exec['pear-discover-channel-phing'],
}
exec { "pear-install-Console_Table":
command => "pear install Console_Table",
unless => "pear info Console_Table",
path => ["/usr/bin"],
logoutput => true,
}
exec { "pear-install-Console_Color2":
command => "pear install Console_Color2-0.1.2",
unless => "pear info Console_Color2-0.1.2",
path => ["/usr/bin"],
logoutput => true,
}
####################################
# Install drush
exec { "git-clone-drush":
command => "git clone https://github.com/drush-ops/drush.git /usr/local/src/drush",
path => ["/usr/bin"],
unless => 'test -d /usr/local/src/drush',
notify => Exec['git-checkout-drush']
}
exec { "git-checkout-drush":
command => "git checkout 6.6.0",
cwd => "/usr/local/src/drush",
path => ["/usr/bin"],
require => Exec['git-clone-drush'],
notify => File['/usr/bin/drush']
}
file { "/usr/bin/drush":
ensure => 'link',
target => '/usr/local/src/drush/drush',
require => Exec['git-checkout-drush'],
notify => Exec['composer-install-drush']
}
exec { "composer-install-drush":
environment => [ "COMPOSER_HOME=/usr/local/src/drush" ],
command => "composer install",
cwd => "/usr/local/src/drush",
path => ["/usr/bin"],
require => File['/usr/bin/drush']
}
# Copy ssh config vagrant file
file { '/home/vagrant/.ssh/config':
ensure => present,
mode => 600,
source => "puppet:///files/ssh/config/default-config",
}
Your problem is probably the same as mine, on which I spent the last couple of days. In my case the problem was with the windows git program.
When you install git under Windows it asks whether you would like to configure CRLF<->LF conversion - there are 3 options:
default, Checkout Windows-style, commit Unix-style line endings - that means convert LF to CRLF when checking out, and convert CRLF to LF when committing,
Checkout as-is, commit Unix-style line encodings - do not convert on check-out, and convert CRLF to LF when committing,
Checkout as-is, commit as-is - do not convert at all.
At first I chose (1), so git converted LF to CRLF when checking out one of the modules, icinga-vagrant\modules\concat, and specifically the script file icinga-vagrant\modules\concat\files\concatfragments.rb. The script then would be copied (without conversion) to the target Linux virtual machine, and wouldn't run there because /usr/bin/env didn't understand what "ruby<CR>" meant, and that's why the error message had a newline in it:
... Could not evaluate: /usr/bin/env: ruby
: No such file or directory
The resolution was to reinstall git with option nr (2), although it can probably be changed without reinstallation - I was a bit lazy. Now, git checks the script as is, with only LF at line ends, and so runs without problems on Linux.
Did you include module stdlib in puppet? concat is one of functions in it. Can you show me the Puppetfile if you manage forge module by librarian-puppet
Seems the dependence is the issue. Should fix your issue after install with it.

Install apache module with puppet on Debian 7

My problem is during the provisionning of my Vagrant VM using puppet. The error is :
==> default: err: /Stage[main]//Service[apache2]: Could not evaluate: Could not find init script for 'apache2'
My puppetFile is the following default.pp :
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
exec { 'apt-get update':
command => 'apt-get update',
timeout => 60,
tries => 3
}
class { 'apt': }
$sysPackages = ['python-software-properties', 'build-essential', 'apache2', 'apache2.2-common']
package { $sysPackages:
ensure => "installed",
require => Exec['apt-get update'],
}
service { apache2:
ensure => running,
enable => true,
require => Package['apache2', 'apache2.2-common'],
}
When not writting the apache2 service, there is no error thrown, but there is no /etc/init.d/apache2. I guess that's why the error is thrown. So how can I avoid this error, or more generaly how to cleanly install this module ?
Any help is welcome.

Error 'invalid parameter include_src' when provisionning RabbitMQ with Puppet on Vagrant

I am trying to install the RabbitMQ module on my virtual machine. I used :
git submodule add https://github.com/puppetlabs/puppetlabs-rabbitmq.git
and I installed every dependecy I could find the same way (which are, like listed in this answer : stdlib, epel, staging and erlang).
I reduced my manifest to the bare minimum :
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
exec { 'apt-get update':
command => 'apt-get update',
timeout => 60,
tries => 3
}
package { ['python-software-properties']:
ensure => 'installed',
require => Exec['apt-get update'],
}
$sysPackages = [ 'build-essential', 'git', 'curl']
package { $sysPackages:
ensure => "installed",
require => Exec['apt-get update'],
}
include epel
include staging
class { 'erlang': epel_enable => true}
class { 'rabbitmq':
port => '5672',
service_manage => true,
environment_variables => {
'RABBITMQ_NODENAME' => 'server',
'RABBITMQ_SERVICENAME' => 'rabbitMQ'
}
}
And when I provision my VM with vagrant provision, I get the error :
==> default: Error: Invalid parameter include_src at /tmp/vagrant-puppet/modules
-33d06c2339c7ee7ab2bd92b2d11cf5d9/erlang/manifests/repo/apt.pp:39
I'm almost certain it is because of a dependency I do not have, but I can not find out which one. Any ideas ?
It seems that erlang module requires older version of apt module. Look at this patch. Recently, in apt resource, parameters include_src and include_deb were substituted by one include parameter. To solve the problem please install apt module in version 1.8.0.

How do I set documentroot for apache with puppet?

I've been trying to get apache to serve from /vagrant/ using puppet through vagrant, my manifest looks like this:
class apache {
exec { 'apt-get update':
command => '/usr/bin/apt-get update'
}
package { "apache2":
ensure => present,
}
service { "apache2":
ensure => running,
require => Package["apache2"],
root => '/vagrant/'
}
}
I would really appreciate the help.... I'm stunned at how bad the manifest documentation is.
easier than changing the httpd.conf with templates etc, it's to make a symlink from /var/www to /vagrant. Add
file { '/var/www':
ensure => 'link',
target => '/vagrant',
force => true,
}
to your puppet file and you are running.
The service resource manages the process but doesn't have anything to do with the configuration files.
Your manifest simply says "Make sure that apt is updated, apache2 is installed and running".
I think what you are looking for can be handled with templates (http://docs.puppetlabs.com/guides/templating.html).