forked from lerndevops/labs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Puppet_Notes.txt
executable file
·303 lines (219 loc) · 7.5 KB
/
Puppet_Notes.txt
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
Manifest 1:
-----------
site.pp:
We'll begin by creating the default manifest, site.pp, in the default location
/etc/puppetlabs/code/environments/production/manifests/site.pp
file {'/tmp/hellodevops': # resource type file and filename
ensure => present, # make sure it exists
mode => '0644', # file permissions
content => "It works on ${ipaddress_eth0}!\n", # Print the eth0 IP fact
}
puppet parser validate site.pp # fir syntax errors
By default Puppet Server runs the commands in its manifests by default every 30 minutes. If the file is removed, the ensure directive will cause it to be recreated. The mode directive will set the file permissions, and the content directive add content to the directive.
We can also test the manifest on a single node using puppet agent --test. Note that --test is not a flag for a dry run; if it's successful, it will change the agent's configuration.
/opt/puppetlabs/bin/puppet agent --test # run on Nodes
You can check the log file on the Puppet master to see when Puppet last compiled the catalog for an agent, which indicates that any changes required should have been applied.
tail /var/log/puppetlabs/puppetserver/puppetserver.log
Manifest 2:
-----------
site.pp
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
# install apache2 package
package { 'apache2':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# ensure apache2 service is running
service { 'apache2':
ensure => running,
}
# 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,
}
# install php5 package
package { 'php7.0':
require => Exec['apt-update'], # require 'apt-update' before installing, v5 for os < v16
ensure => installed,
}
# ensure info.php file exists
file { '/var/www/html/info.php':
ensure => file,
content => '<?php phpinfo(); ?>', # phpinfo code
require => Package['apache2'], # require 'apache2' package before creating
}
Manifest 3:
-----------
tou may use node definitions with class also
node 'nodename'{
class{'linux':}
}
node 'node2'{
other code
}
class linux{
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
# install apache2 package
package { 'apache2':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# ensure apache2 service is running
service { 'apache2':
ensure => running,
}
}
Manifest 4:
-----------
site.pp
# remove git on remote node
node 'ip-172-31-23-98.ap-south-1.compute.internal'{
class{'linux':}
}
class linux{
# execute 'apt-get update'
$soft=['git','vim']
exec { 'apt-update':
command => '/usr/bin/apt-get update'
}
# install soft
package {$soft:
require => Exec['apt-update'],
ensure => installed,
}
}
Puppet Environment:
-------------------
By default node is connecting to production and calling site.pp
we can create another env on master.
/etc/puppetlabs/code/environments# mkdir QA
/etc/puppetlabs/code/environments# cd QA
/etc/puppetlabs/code/environments/QA# mkdir manifests
/etc/puppetlabs/code/environments/QA# cd manifests/
create manifest here
site.pp
node 'ip-172-31-23-98.ap-south-1.compute.internal'{
file{'/tmp/QAEnvFile':
ensure => 'present',
content => " created from QA ENV"
}
}
NOW go back to Nodes
open /etc/puppetlabs/puppet/puppet.conf
edit and enter below value
environment=QA
/opt/puppetlabs/bin/puppet agent --test
Automatic Pull:
--------------
go to node puppet.conf and edit runinterval=1m or 2m
/etc/puppetlabs/puppet# vi puppet.conf
runinterval=1m
now you will see the change on node in 1 min
Modules:
-----------
we are building a project with modules..
php, apache,mysql,code
go to production folder om master
mkdir modules
cd modules
puppet module generate ravi-site --environment production
now module will be created (it asks a few questions.. just follow)
root@ip-172-31-26-231:/etc/puppetlabs/code/environments/production/modules/ravi-site# ls -ltr
total 28
drwxr-xr-x 2 root root 4096 Dec 9 09:35 tests
drwxr-xr-x 3 root root 4096 Dec 9 09:35 spec
-rw-r--r-- 1 root root 2891 Dec 9 09:35 README.md
-rw-r--r-- 1 root root 633 Dec 9 09:35 Rakefile
-rw-r--r-- 1 root root 268 Dec 9 09:35 metadata.json
drwxr-xr-x 2 root root 4096 Dec 9 09:35 manifests
-rw-r--r-- 1 root root 242 Dec 9 09:35 Gemfile
Go to Manifests.. it has init.pp
now init.pp contains default class with the name we have, now start editing.
step1: edit class section with below code
class site {
package{'php-mysql':,
ensure => 'present',
}
package{'php-xml':,
ensure => 'present',
}
}
By default our nodes talk to only site.pp under production/manifests.
Now we need to include our init.pp as part of site.pp
our site.pp:
------------
node 'ip-172-31-23-98.ap-south-1.compute.internal'{
class{'linux':}
class{'site':} # this is from our site module
}
class linux{
# execute 'apt-get update'
$soft=['git','vim']
exec { 'apt-update':
command => '/usr/bin/apt-get update'
}
# install soft
package {$soft:
require => Exec['apt-update'],
ensure => installed,
}
}
=====================================================================================
node 'ip-172-31-12-122.us-east-2.compute.internal'{
file {'/tmp/node1': # resource type file and filename
ensure => present, # make sure it exists
mode => '0644', # file permissions
content => "It works on ${ipaddress_eth0}!\n", # Print the eth0 IP fact
}
class{'node1':}
}
node 'ip-172-31-0-235.us-east-2.compute.internal'{
file {'/tmp/node2': # resource type file and filename
ensure => present, # make sure it exists
mode => '0644', # file permissions
content => "It works on ${ipaddress_eth0}!\n", # Print the eth0 IP fact
}
class{'node2':}
}
class node1{
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
# install apache2 package
package { 'nginx':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# ensure apache2 service is running
service { 'nginx':
ensure => running,
}
}
class node2{
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
# install apache2 package
package { 'apache2':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}
# ensure apache2 service is running
service { 'apache2':
ensure => running,
}
}
Puppet Tutorial : https://www.example42.com/tutorials/PuppetTutorial/