/
common.pp
228 lines (209 loc) · 8.33 KB
/
common.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# == Class: contrail::common
#
# This class is used to configure software and services common
# to all contrail modules.
#
# === Parameters:
#
# [*host_mgmt_ip*]
# IP address of the server where contrail modules are being installed.
# if server has separate interfaces for management and control, this
# parameter should provide management interface IP address.
#
# [*contrail_repo_name*]
# Name of contrail repo being used to provision the contrail roles.
# Version of contrail software being used is specified here.
#
# [*contrail_repo_ip*]
# IP address of the server where contrail repo is mirrored. This is
# same as the cobbler address or server manager IP address (puppet master).
#
# [*contrail_repo_type*]
# Type of contrail repo (contrail-ubuntu-package or contrail-centos-package).
#
class contrail::common(
$host_mgmt_ip = $::contrail::params::host_ip,
$contrail_repo_name = $::contrail::params::contrail_repo_name,
$contrail_repo_ip = $::contrail::params::contrail_repo_ip,
$contrail_repo_type = $::contrail::params::contrail_repo_type
) inherits ::contrail::params {
notify { "**** $module_name - host_mgmt_ip = $host_mgmt_ip": ; }
notify { "**** $module_name - contrail_repo_name = $contrail_repo_name": ; }
notify { "**** $module_name - contrail_repo_ip = $contrail_repo_ip": ; }
notify { "**** $module_name - contrail_repo_type = $contrail_repo_type": ; }
$contrail_users_details = {
'nova' => { user_uid => '499', user_group_name => 'nova', group_gid => '499', user_home_dir => '/var/lib/nova' },
'libvirt-qemu' => { user_uid => '498', user_group_name => 'kvm' , group_gid => '498', user_home_dir => '/var/lib/libvirt'},
'libvirt-dnsmasq' => { user_uid => '497', user_group_name => 'libvirtd' , group_gid => '497', user_home_dir => '/var/lib/libvirt/dnsmasq'},
}
create_resources(contrail::lib::setup_uid, $contrail_users_details, {})
# Resource declarations for class contrail::common
# macro to perform common functions
# Create repository config on target.
contrail::lib::contrail-setup-repo{ $contrail_repo_name:
#contrail_repo_name => $contrail_repo_name,
contrail_repo_ip => $contrail_repo_ip
} ->
contrail::lib::contrail-install-repo{ $contrail_repo_type:
#contrail_repo_type => $contrail_repo_type
}
->
contrail::lib::upgrade-kernel{ kernel_upgrade:
contrail_kernel_upgrade => $kernel_upgrade,
contrail_kernel_version => $kernel_version
} ->
# Ensure /etc/hosts has an entry for self to map dns name to ip address
host { "$hostname" :
ensure => present,
ip => "$host_mgmt_ip"
}
->
exec { "setmysql" :
#command => "python /etc/contrail/contrail_setup_utils/enable_kernel_core.py && echo enable-kernel-core >> /etc/contrail/contrail_common_exec.out",
command => "mkdir -p /var/log/mysql && echo setmysql >> /etc/contrail/contrail_common_exec.out",
unless => "grep -qx setmysql /etc/contrail/contrail_common_exec.out",
provider => shell,
logoutput => "true"
}
->
package { 'libssl0.9.8' : ensure => present,}
# Disable SELINUX on boot, if not already disabled.
if ($operatingsystem == "Centos" or $operatingsystem == "Fedora") {
exec { "selinux-dis-1" :
command => "sed -i \'s/SELINUX=.*/SELINUX=disabled/g\' config",
cwd => '/etc/selinux',
onlyif => '[ -d /etc/selinux ]',
unless => "grep -qFx 'SELINUX=disabled' '/etc/selinux/config'",
provider => shell,
logoutput => "true"
}
# disable selinux runtime
exec { "selinux-dis-2" :
command => "setenforce 0 || true",
unless => "getenforce | grep -qi disabled",
provider => shell,
logoutput => "true"
}
# Disable iptables
service { "iptables" :
enable => false,
ensure => stopped
}
}
if ($operatingsystem == "Ubuntu") {
# disable firewall
exec { "disable-ufw" :
command => "ufw disable",
unless => "ufw status | grep -qi inactive",
provider => shell,
logoutput => "true"
}
# Create symbolic link to chkconfig. This does not exist on Ubuntu.
file { '/sbin/chkconfig':
ensure => link,
target => '/bin/true'
}
}
# Flush ip tables.
exec { 'iptables --flush': provider => shell, logoutput => true }
# Remove any core limit configured
if ($operatingsystem == "Centos" or $operatingsystem == "Fedora") {
exec { 'daemon-core-file-unlimited':
command => "sed -i \'/DAEMON_COREFILE_LIMIT=.*/d\' /etc/sysconfig/init; echo DAEMON_COREFILE_LIMIT=\"\'unlimited\'\" >> /etc/sysconfig/init",
unless => "grep -qx \"DAEMON_COREFILE_LIMIT='unlimited'\" /etc/sysconfig/init",
provider => shell,
logoutput => "true"
}
}
if ($operatingsystem == "Ubuntu") {
exec { "core-file-unlimited" :
command => "ulimit -c unlimited",
unless => "ulimit -c | grep -qi unlimited",
provider => shell,
logoutput => "true"
}
}
##HACk for mysql on openstack-ha
if ($::contrail::params::internal_vip != "") {
file { "/opt/check-mysql-status.py" :
ensure => present,
mode => 0755,
group => root,
source => "puppet:///modules/$module_name/check-mysql-status.py"
}
->
exec { "exec_check_mysql" :
command => "python /opt/check-mysql-status.py",
cwd => "/opt/",
# unless => "grep -qx exec_check_mysql /etc/contrail/contrail_common_exec.out",
provider => shell,
require => [ File["/opt/check-mysql-status.py"] ],
logoutput => 'true',
}
}
# Core pattern
exec { 'core_pattern_1':
command => 'echo \'kernel.core_pattern = /var/crashes/core.%e.%p.%h.%t\' >> /etc/sysctl.conf',
unless => "grep -q 'kernel.core_pattern = /var/crashes/core.%e.%p.%h.%t' /etc/sysctl.conf",
provider => shell,
logoutput => "true"
}
# Enable ip forwarding in sysctl.conf for vgw
exec { 'enable-ipf-for-vgw':
command => "sed -i \"s/net.ipv4.ip_forward.*/net.ipv4.ip_forward = 1/g\" /etc/sysctl.conf",
unless => ["[ ! -f /etc/sysctl.conf ]",
"grep -qx \"net.ipv4.ip_forward = 1\" /etc/sysctl.conf"],
provider => shell,
logoutput => "true"
}
#exec { 'sysctl -e -p' : provider => shell, logoutput => on_failure }
file { "/var/crashes":
ensure => "directory",
}
# Make sure our scripts directory is present
file { ["/etc/contrail", "/etc/contrail/contrail_setup_utils"] :
ensure => "directory",
}
# Enable kernel core.
file { "/etc/contrail/contrail_setup_utils/enable_kernel_core.py":
ensure => present,
mode => 0755,
owner => root,
group => root,
source => "puppet:///modules/$module_name/enable_kernel_core.py"
}
# enable kernel core , below python code has bug, for now ignore by executing echo regardless and thus returning true for cmd.
# need to revisit afterwards.
exec { "enable-kernel-core" :
#command => "python /etc/contrail/contrail_setup_utils/enable_kernel_core.py && echo enable-kernel-core >> /etc/contrail/contrail_common_exec.out",
command => "python /etc/contrail/contrail_setup_utils/enable_kernel_core.py; echo enable-kernel-core >> /etc/contrail/contrail_common_exec.out",
require => File["/etc/contrail/contrail_setup_utils/enable_kernel_core.py" ],
unless => "grep -qx enable-kernel-core /etc/contrail/contrail_common_exec.out",
provider => shell,
logoutput => "true"
}
file { "/tmp/facts.yaml":
content => inline_template("<%= scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }.to_yaml %>"),
}
# if ( ($internal_vip != "" and $internal_vip != undef) or
# ($contrail_internal_vip != "" and $contrail_internal_vip != undef) or
# ($external_vip != "" and $external_vip != undef) or
# ($contrail_external_vip != "" and $contrail_external_vip != undef))
#set the reserved ports
# {
file { "/opt/contrail/bin/add_reserved_ports.py" :
ensure => present,
mode => 0755,
group => root,
source => "puppet:///modules/$module_name/add_reserved_ports.py"
}
->
exec { "add_reserved_ports" :
command => "python add_reserved_ports.py 35357,35358,33306 && echo add_reserved_ports >> /etc/contrail/contrail_common_exec.out",
cwd => "/opt/contrail/bin/",
unless => "grep -qx add_reserved_ports /etc/contrail/contrail_common_exec.out",
provider => shell,
logoutput => 'true'
}
}
#}