5bbcd7506a1a5b3624fc569da491322b21f573f6
[releng.git] / prototypes / puppet-infracloud / modules / opnfv / manifests / server.pp
1 # SPDX-license-identifier: Apache-2.0
2 ##############################################################################
3 # Copyright (c) 2016 RedHat and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 class opnfv::server (
10   $iptables_public_tcp_ports = [],
11   $iptables_public_udp_ports = [],
12   $iptables_rules4           = [],
13   $iptables_rules6           = [],
14   $sysadmins                 = [],
15   $enable_unbound            = true,
16   $purge_apt_sources         = true,
17 ) {
18   ###########################################################
19   # Classes for all hosts
20
21   include snmpd
22   include sudoers
23
24   class { 'iptables':
25     public_tcp_ports => $iptables_public_tcp_ports,
26     public_udp_ports => $all_udp,
27     rules4           => $iptables_rules4,
28     rules6           => $iptables_rules6,
29   }
30
31   class { 'timezone':
32     timezone => 'Etc/UTC',
33   }
34
35   if ($enable_unbound) {
36     class { 'unbound':
37       install_resolv_conf => $install_resolv_conf
38     }
39   }
40
41   if ($::in_chroot) {
42     notify { 'rsyslog in chroot':
43       message => 'rsyslog not refreshed, running in chroot',
44     }
45     $rsyslog_notify = []
46   } else {
47     service { 'rsyslog':
48       ensure     => running,
49       enable     => true,
50       hasrestart => true,
51       require    => Package['rsyslog'],
52     }
53     $rsyslog_notify = [ Service['rsyslog'] ]
54   }
55
56   ###########################################################
57   # System tweaks
58
59   # Increase syslog message size in order to capture
60   # python tracebacks with syslog.
61   file { '/etc/rsyslog.d/99-maxsize.conf':
62     ensure  => present,
63     # Note MaxMessageSize is not a puppet variable.
64     content => '$MaxMessageSize 6k',
65     owner   => 'root',
66     group   => 'root',
67     mode    => '0644',
68     notify  => $rsyslog_notify,
69     require => Package['rsyslog'],
70   }
71
72   # We don't like byobu
73   file { '/etc/profile.d/Z98-byobu.sh':
74     ensure => absent,
75   }
76
77   if $::osfamily == 'Debian' {
78
79     # Ubuntu installs their whoopsie package by default, but it eats through
80     # memory and we don't need it on servers
81     package { 'whoopsie':
82       ensure => absent,
83     }
84
85     package { 'popularity-contest':
86       ensure => absent,
87     }
88   }
89
90   ###########################################################
91   # Package resources for all operating systems
92
93   package { 'at':
94     ensure => present,
95   }
96
97   package { 'lvm2':
98     ensure => present,
99   }
100
101   package { 'strace':
102     ensure => present,
103   }
104
105   package { 'tcpdump':
106     ensure => present,
107   }
108
109   package { 'rsyslog':
110     ensure => present,
111   }
112
113   package { 'git':
114     ensure => present,
115   }
116
117   package { 'rsync':
118     ensure => present,
119   }
120
121   case $::osfamily {
122     'RedHat': {
123       $packages = ['parted', 'puppet', 'wget', 'iputils']
124       $user_packages = ['emacs-nox', 'vim-enhanced']
125       $update_pkg_list_cmd = ''
126     }
127     'Debian': {
128       $packages = ['parted', 'puppet', 'wget', 'iputils-ping']
129       case $::operatingsystemrelease {
130         /^(12|14)\.(04|10)$/: {
131           $user_packages = ['emacs23-nox', 'vim-nox', 'iftop',
132                             'sysstat', 'iotop']
133         }
134         default: {
135           $user_packages = ['emacs-nox', 'vim-nox']
136         }
137       }
138       $update_pkg_list_cmd = 'apt-get update >/dev/null 2>&1;'
139     }
140     default: {
141       fail("Unsupported osfamily: ${::osfamily} The 'openstack_project' module only supports osfamily Debian or RedHat (slaves only).")
142     }
143   }
144   package { $packages:
145     ensure => present
146   }
147
148   ###########################################################
149   # Package resources for specific operating systems
150
151   case $::osfamily {
152     'Debian': {
153       # Purge and augment existing /etc/apt/sources.list if requested, and make
154       # sure apt-get update is run before any packages are installed
155       class { '::apt':
156         purge => { 'sources.list' => $purge_apt_sources }
157       }
158
159       # Make sure dig is installed
160       package { 'dnsutils':
161         ensure => present,
162       }
163     }
164     'RedHat': {
165       # Make sure dig is installed
166       package { 'bind-utils':
167         ensure => present,
168       }
169     }
170   }
171
172   ###########################################################
173   # Manage  ntp
174
175   include '::ntp'
176
177   if ($::osfamily == "RedHat") {
178     # Utils in ntp-perl are included in Debian's ntp package; we
179     # add it here for consistency.  See also
180     # https://tickets.puppetlabs.com/browse/MODULES-3660
181     package { 'ntp-perl':
182       ensure => present
183     }
184     # NOTE(pabelanger): We need to ensure ntpdate service starts on boot for
185     # centos-7.  Currently, ntpd explicitly require ntpdate to be running before
186     # the sync process can happen in ntpd.  As a result, if ntpdate is not
187     # running, ntpd will start but fail to sync because of DNS is not properly
188     # setup.
189     package { 'ntpdate':
190       ensure => present,
191     }
192     service { 'ntpdate':
193       enable => true,
194       require => Package['ntpdate'],
195     }
196   }
197
198   ###########################################################
199   # Manage  python/pip
200
201   $desired_virtualenv = '13.1.0'
202   class { '::pip':
203     optional_settings => {
204       'extra-index-url' => '',
205     },
206     manage_pip_conf => true,
207   }
208
209   if (( versioncmp($::virtualenv_version, $desired_virtualenv) < 0 )) {
210     $virtualenv_ensure = $desired_virtualenv
211   } else {
212     $virtualenv_ensure = present
213   }
214   package { 'virtualenv':
215     ensure   => $virtualenv_ensure,
216     provider => openstack_pip,
217     require  => Class['pip'],
218   }
219
220   # add hosts entries
221   create_resources('host', hiera_hash('hosts'))
222 }