Puppet Class: apache
- Inherits:
- apache::params
- Defined in:
- manifests/init.pp
Summary
Guides the basic setup and installation of Apache on your system.Overview
When this class is declared with the default options, Puppet:
-
Installs the appropriate Apache software package and [required Apache modules](#default_mods) for your operating system.
-
Places the required configuration files in a directory, with the [default location](#conf_dir) determined by your operating system.
-
Configures the server with a default virtual host and standard port (‘80`) and address (`*`) bindings.
-
Creates a document root directory determined by your operating system, typically ‘/var/www`.
-
Starts the Apache service.
If an ldaps:// URL is specified, the mode becomes SSL and the setting of LDAPTrustedMode is ignored.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'manifests/init.pp', line 450
class apache (
String $apache_name = $apache::params::apache_name,
String $service_name = $apache::params::service_name,
Variant[Array[String[1]], Boolean] $default_mods = true,
Boolean $default_vhost = true,
Optional[String] $default_charset = undef,
Boolean $default_confd_files = true,
Boolean $default_ssl_vhost = false,
Stdlib::Absolutepath $default_ssl_cert = $apache::params::default_ssl_cert,
Stdlib::Absolutepath $default_ssl_key = $apache::params::default_ssl_key,
Optional[Stdlib::Absolutepath] $default_ssl_chain = undef,
Optional[Stdlib::Absolutepath] $default_ssl_ca = undef,
Optional[Stdlib::Absolutepath] $default_ssl_crl_path = undef,
Optional[Stdlib::Absolutepath] $default_ssl_crl = undef,
Optional[String] $default_ssl_crl_check = undef,
Boolean $default_ssl_reload_on_change = false,
Optional[Variant[Array, String]] $dev_packages = $apache::params::dev_packages,
Optional[String] $ip = undef,
Boolean $service_enable = true,
Boolean $service_manage = true,
Variant[Stdlib::Ensure::Service, Boolean] $service_ensure = 'running',
Optional[String] $service_restart = undef,
Boolean $purge_configs = true,
Optional[Boolean] $purge_vhost_dir = undef,
Optional[String[1]] $serveradmin = undef,
Apache::OnOff $sendfile = 'On',
Optional[Apache::OnOff] $ldap_verify_server_cert = undef,
Optional[String] $ldap_trusted_mode = undef,
Boolean $error_documents = false,
Integer[0] $timeout = 60,
Stdlib::Absolutepath $httpd_dir = $apache::params::httpd_dir,
Stdlib::Absolutepath $server_root = $apache::params::server_root,
Stdlib::Absolutepath $conf_dir = $apache::params::conf_dir,
Stdlib::Absolutepath $confd_dir = $apache::params::confd_dir,
Variant[Apache::OnOff, Enum['Double', 'double']] $hostname_lookups = $apache::params::hostname_lookups,
Optional[Stdlib::Absolutepath] $conf_enabled = $apache::params::conf_enabled,
Stdlib::Absolutepath $vhost_dir = $apache::params::vhost_dir,
Optional[Stdlib::Absolutepath] $vhost_enable_dir = $apache::params::vhost_enable_dir,
Boolean $manage_vhost_enable_dir = true,
Hash $mod_libs = $apache::params::mod_libs,
Hash $mod_packages = $apache::params::mod_packages,
String $vhost_include_pattern = $apache::params::vhost_include_pattern,
Stdlib::Absolutepath $mod_dir = $apache::params::mod_dir,
Optional[Stdlib::Absolutepath] $mod_enable_dir = $apache::params::mod_enable_dir,
Variant[Boolean, Enum['event', 'itk', 'peruser', 'prefork', 'worker']] $mpm_module = $apache::params::mpm_module,
String $lib_path = $apache::params::lib_path,
String $conf_template = $apache::params::conf_template,
Optional[String] $servername = $apache::params::servername,
String $pidfile = $apache::params::pidfile,
Boolean $manage_user = true,
Boolean $manage_group = true,
String $user = $apache::params::user,
String $group = $apache::params::group,
Optional[String] $http_protocol_options = $apache::params::http_protocol_options,
Array $supplementary_groups = [],
Apache::OnOff $keepalive = $apache::params::keepalive,
Integer $keepalive_timeout = $apache::params::keepalive_timeout,
Integer $max_keepalive_requests = $apache::params::max_keepalive_requests,
Integer $limitreqfieldsize = 8190,
Integer $limitreqfields = 100,
Optional[Integer] $limitreqline = undef,
Stdlib::Absolutepath $logroot = $apache::params::logroot,
Optional[Stdlib::Filemode] $logroot_mode = $apache::params::logroot_mode,
Apache::LogLevel $log_level = $apache::params::log_level,
Hash $log_formats = {},
Optional[String] $ssl_file = undef,
Stdlib::Absolutepath $ports_file = $apache::params::ports_file,
Stdlib::Absolutepath $docroot = $apache::params::docroot,
Apache::ServerTokens $server_tokens = 'Prod',
Variant[Apache::OnOff, String] $server_signature = 'On',
Variant[Apache::OnOff, Enum['extended']] $trace_enable = 'On',
Optional[Variant[Apache::OnOff, Enum['nodecode']]] $allow_encoded_slashes = undef,
Optional[String] $file_e_tag = undef,
Optional[Variant[Apache::OnOff, Enum['DNS', 'dns']]] $use_canonical_name = undef,
String $package_ensure = 'installed',
Boolean $use_optional_includes = $apache::params::use_optional_includes,
Boolean $use_systemd = $apache::params::use_systemd,
Hash $mime_types_additional = $apache::params::mime_types_additional,
Stdlib::Filemode $file_mode = $apache::params::file_mode,
Array $root_directory_options = $apache::params::root_directory_options,
Boolean $root_directory_secured = false,
String $error_log = $apache::params::error_log,
String $scriptalias = $apache::params::scriptalias,
String $access_log_file = $apache::params::access_log_file,
Array[Enum['h2', 'h2c', 'http/1.1']] $protocols = [],
Optional[Boolean] $protocols_honor_order = undef,
) inherits apache::params {
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '7' {
# On RedHat 7 the ssl.conf lives in /etc/httpd/conf.d (the confd_dir)
# when all other module configs live in /etc/httpd/conf.modules.d (the
# mod_dir). On all other platforms and versions, ssl.conf lives in the
# mod_dir. This should maintain the expected location of ssl.conf
$_ssl_file = $ssl_file ? {
undef => "${apache::confd_dir}/ssl.conf",
default => $ssl_file
}
} else {
$_ssl_file = $ssl_file ? {
undef => "${apache::mod_dir}/ssl.conf",
default => $ssl_file
}
}
# NOTE: on FreeBSD it's mpm module's responsibility to install httpd package.
# NOTE: the same strategy may be introduced for other OSes. For this, you
# should delete the 'if' block below and modify all MPM modules' manifests
# such that they include apache::package class (currently event.pp, itk.pp,
# peruser.pp, prefork.pp, worker.pp).
if $facts['os']['family'] != 'FreeBSD' {
package { 'httpd':
ensure => $package_ensure,
name => $apache_name,
notify => Class['Apache::Service'],
}
}
# declare the web server user and group
# Note: requiring the package means the package ought to create them and not puppet
if $manage_user {
user { $user:
ensure => present,
gid => $group,
groups => $supplementary_groups,
require => Package['httpd'],
}
}
if $manage_group {
group { $group:
ensure => present,
require => Package['httpd'],
}
}
class { 'apache::service':
service_name => $service_name,
service_enable => $service_enable,
service_manage => $service_manage,
service_ensure => $service_ensure,
service_restart => $service_restart,
}
# Set purge vhostd appropriately
if $purge_vhost_dir == undef {
$purge_vhostd = $purge_configs
} else {
$purge_vhostd = $purge_vhost_dir
}
Exec {
path => '/bin:/sbin:/usr/bin:/usr/sbin',
}
$confd_command = ['mkdir', $confd_dir]
exec { "mkdir ${confd_dir}":
command => $confd_command,
creates => $confd_dir,
require => Package['httpd'],
}
file { $confd_dir:
ensure => directory,
recurse => true,
purge => $purge_configs,
force => $purge_configs,
notify => Class['Apache::Service'],
require => Package['httpd'],
}
if $conf_enabled and ! defined(File[$conf_enabled]) {
file { $conf_enabled:
ensure => directory,
recurse => true,
purge => $purge_configs,
force => $purge_configs,
notify => Class['Apache::Service'],
require => Package['httpd'],
}
}
if ! defined(File[$mod_dir]) {
$mod_command = ['mkdir', $mod_dir]
exec { "mkdir ${mod_dir}":
command => $mod_command,
creates => $mod_dir,
require => Package['httpd'],
}
# Don't purge available modules if an enable dir is used
$purge_mod_dir = $purge_configs and !$mod_enable_dir
file { $mod_dir:
ensure => directory,
recurse => true,
purge => $purge_mod_dir,
notify => Class['Apache::Service'],
require => Package['httpd'],
before => Anchor['::apache::modules_set_up'],
}
}
if $mod_enable_dir and ! defined(File[$mod_enable_dir]) {
$mod_load_dir = $mod_enable_dir
$mod_enable_command = ['mkdir', $mod_enable_dir]
exec { "mkdir ${mod_enable_dir}":
command => $mod_enable_command,
creates => $mod_enable_dir,
require => Package['httpd'],
}
file { $mod_enable_dir:
ensure => directory,
recurse => true,
purge => $purge_configs,
notify => Class['Apache::Service'],
require => Package['httpd'],
}
} else {
$mod_load_dir = $mod_dir
}
if ! defined(File[$vhost_dir]) {
$vhost_command = ['mkdir', $vhost_dir]
exec { "mkdir ${vhost_dir}":
command => $vhost_command,
creates => $vhost_dir,
require => Package['httpd'],
}
file { $vhost_dir:
ensure => directory,
recurse => true,
purge => $purge_vhostd,
notify => Class['Apache::Service'],
require => Package['httpd'],
}
}
if $vhost_enable_dir and ! defined(File[$vhost_enable_dir]) and $manage_vhost_enable_dir {
$vhost_load_dir = $vhost_enable_dir
$vhost_load_command = ['mkdir', $vhost_load_dir]
exec { "mkdir ${vhost_load_dir}":
command => $vhost_load_command,
creates => $vhost_load_dir,
require => Package['httpd'],
}
file { $vhost_enable_dir:
ensure => directory,
recurse => true,
purge => $purge_vhostd,
notify => Class['Apache::Service'],
require => Package['httpd'],
}
} else {
$vhost_load_dir = $vhost_dir
}
concat { $ports_file:
ensure => present,
owner => 'root',
group => $apache::params::root_group,
mode => $apache::file_mode,
notify => Class['Apache::Service'],
require => Package['httpd'],
}
concat::fragment { 'Apache ports header':
target => $ports_file,
content => epp('apache/ports_header.epp'),
}
if $apache::conf_dir and $apache::params::conf_file {
if $facts['os']['family'] == 'Gentoo' {
$error_documents_path = '/usr/share/apache2/error'
if $default_mods =~ Array {
if defined('apache::mod::ssl') {
::portage::makeconf { 'apache2_modules':
content => concat($default_mods, ['authz_core', 'socache_shmcb']),
}
} else {
::portage::makeconf { 'apache2_modules':
content => concat($default_mods, 'authz_core'),
}
}
}
file { [
'/etc/apache2/modules.d/.keep_www-servers_apache-2',
'/etc/apache2/vhosts.d/.keep_www-servers_apache-2',
]:
ensure => absent,
require => Package['httpd'],
}
}
$apxs_workaround = $facts['os']['family'] ? {
'FreeBSD' => true,
default => false
}
# Template uses:
# - $pidfile
# - $user
# - $group
# - $logroot
# - $error_log
# - $sendfile
# - $mod_dir
# - $ports_file
# - $confd_dir
# - $vhost_dir
# - $error_documents
# - $error_documents_path
# - $apxs_workaround
# - $http_protocol_options
# - $keepalive
# - $keepalive_timeout
# - $max_keepalive_requests
# - $server_root
# - $server_tokens
# - $server_signature
# - $trace_enable
# - $root_directory_secured
$parameters = {
'server_tokens' => $server_tokens,
'server_signature' => $server_signature,
'trace_enable' => $trace_enable,
'servername' => $servername,
'server_root' => $server_root,
'serveradmin' => $serveradmin,
'pidfile' => $pidfile,
'timeout' => $timeout,
'keepalive' => $keepalive,
'max_keepalive_requests' => $max_keepalive_requests,
'keepalive_timeout' => $keepalive_timeout,
'limitreqfieldsize' => $limitreqfieldsize,
'limitreqfields' => $limitreqfields,
'limitreqline' => $limitreqline,
'http_protocol_options' => $http_protocol_options,
'protocols' => $protocols,
'protocols_honor_order' => $protocols_honor_order,
'user' => $user,
'group' => $group,
'root_directory_options' => $root_directory_options,
'root_directory_secured' => $root_directory_secured,
'default_charset' => $default_charset,
'hostname_lookups' => $hostname_lookups,
'error_log' => $error_log,
'logroot' => $logroot,
'log_level' => $log_level,
'sendfile' => $sendfile,
'allow_encoded_slashes' => $allow_encoded_slashes,
'file_e_tag' => $file_e_tag,
'use_canonical_name' => $use_canonical_name,
'apxs_workaround' => $apxs_workaround,
'mod_load_dir' => $mod_load_dir,
'confd_dir' => $confd_dir,
'vhost_load_dir' => $vhost_load_dir,
'vhost_include_pattern' => $vhost_include_pattern,
'ports_file' => $ports_file,
'log_formats' => $log_formats,
'conf_enabled' => $conf_enabled,
'ldap_verify_server_cert' => $ldap_verify_server_cert,
'ldap_trusted_mode' => $ldap_trusted_mode,
'error_documents' => $error_documents,
'error_documents_path' => $error_documents_path,
}
file { "${apache::conf_dir}/${apache::params::conf_file}":
ensure => file,
mode => $apache::file_mode,
content => epp($conf_template, $parameters),
notify => Class['Apache::Service'],
require => [Package['httpd'], Concat[$ports_file]],
}
# preserve back-wards compatibility to the times when default_mods was
# only a boolean value. Now it can be an array (too)
if $default_mods =~ Array {
class { 'apache::default_mods':
all => false,
mods => $default_mods,
}
} else {
class { 'apache::default_mods':
all => $default_mods,
}
}
class { 'apache::default_confd_files':
all => $default_confd_files,
}
if $mpm_module and $mpm_module != 'false' { # lint:ignore:quoted_booleans
include "::apache::mod::${mpm_module}"
}
if 'h2' in $protocols or 'h2c' in $protocols {
include apache::mod::http2
}
$default_vhost_ensure = $default_vhost ? {
true => 'present',
false => 'absent'
}
$default_ssl_vhost_ensure = $default_ssl_vhost ? {
true => 'present',
false => 'absent'
}
::apache::vhost { 'default':
ensure => $default_vhost_ensure,
port => 80,
docroot => $docroot,
scriptalias => $scriptalias,
serveradmin => $serveradmin,
access_log_file => $access_log_file,
priority => 15,
ip => $ip,
logroot_mode => $logroot_mode,
manage_docroot => $default_vhost,
use_servername_for_filenames => true,
use_port_for_filenames => true,
}
$ssl_access_log_file = $facts['os']['family'] ? {
'FreeBSD' => $access_log_file,
default => "ssl_${access_log_file}",
}
::apache::vhost { 'default-ssl':
ensure => $default_ssl_vhost_ensure,
port => 443,
ssl => true,
docroot => $docroot,
scriptalias => $scriptalias,
serveradmin => $serveradmin,
access_log_file => $ssl_access_log_file,
priority => 15,
ip => $ip,
logroot_mode => $logroot_mode,
manage_docroot => $default_ssl_vhost,
use_servername_for_filenames => true,
use_port_for_filenames => true,
}
}
# This anchor can be used as a reference point for things that need to happen *after*
# all modules have been put in place.
anchor { '::apache::modules_set_up': }
}
|