GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — DevOps_ClassNotes/Puppet/puppet_Notes.txt at master · Sonal0409/DevOps_ClassNotes Expand file tree/ Copy pathpuppet_Notes.txtMore file actions 762 lines (381 loc) · 9.82 KB / Copy pathpuppet_Notes.txtFile metadata and controls762 lines (381 loc) · 9.82 KB 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 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 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 Start 2 Instances in AWS: Note down prive ip and Hostname of Puppetserver private ip : 172.31.10.193 private hostname: ip-172-31-10-193.us-east-2.compute.internal Note down prive ip and Hostname of PuppetAgent private ip: 172.31.9.221 private hostname: ip-172-31-9-221.us-east-2.compute.internal Start the AWS machines Open 2 Bash instances start one for puppet server start one for puppetAgent ON PUPPET SERVER ************************* # sudo su - # vim /etc/hosts // open this file and add below details on top of file Add the private ip and provate hostname of pupperserver first Add the private ip and private hostname of puppet agent in next line 172.31.10.193 ip-172-31-10-193.us-east-2.compute.internal 172.31.9.221 ip-172-31-9-221.us-east-2.compute.internal ON PuppetAGent *********************** Repeat above steps: # sudo su - # vim /etc/hosts // open this file and add below details on top of file Add the private ip and provate hostname of pupperserver first Add the private ip and private hostname of puppet agent in next line 172.31.10.193 ip-172-31-10-193.us-east-2.compute.internal 172.31.9.221 ip-172-31-9-221.us-east-2.compute.internal Go back to PUPPETSERVER -SETUP ********************************** 1. Download the puppet package # rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm 2. Download puppetserver now # yum install puppetserver -y 3. Add server dns name in this file # vim /etc/puppetlabs/puppet/puppet.conf Add master private dns_hostname above vardir and after [master] dns_alt_names=ip-172-31-10-193.us-east-2.compute.internal 4. Update JAVA_ARGS from 2g to 512m # vim /etc/sysconfig/puppetserver Update this line in above file # Modify this if you'd like to change the memory allocation, enable JMX, etc JAVA_ARGS="-Xms512m -Xmx512m -Djruby.logger.class=com.puppetlabs.jruby_utils.jruby.Slf4jLogger" 5.restart the system # exec bash -l 6. Start puppetserver # systemctl start puppetserver It will take time start server.. meanwhile setup puppetAgent *********************************** PuppetAGENT setup 1. download puppet package # rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm 2. Download puppet package # yum install puppet -y 3. vim /etc/puppetlabs/puppet/puppet.conf Add master private hostname of server as given below, at the end of all # server=ip-172-31-10-193.us-east-2.compute.internal 4. restart bash # exec bash -l Check if puppet Server is started and only then start Agent 5. Start puppet # systemctl start puppet Complete set up **************************** Check if host and server are connected or not. Check if host is able to pull the catalogue form server or not. On Agent machine: command to pull catalogue is: # puppet agent --test it will give message as : Exiting; no certificate found and waitforcert is disabled That means, puppetagent has sent the facts to the master but master has not sigend the certificate. once server/master signs the certificate, agent will be able to pull the catalogue and apply the configurations. Go to PuppetServer machine to generate certificate and sign the certificate # puppet cert list --all will give list of certificates for all the agents that are connected to the host the first row has the certificate that for our agent and is not signed ip-172-31-9-221.us-east-2.compute.internal Copy it as given above and execute this command # puppet cert sign ip-172-31-9-221.us-east-2.compute.internal This will sign the certificate ********************** Go to Agent ************ # puppet agent --test Now catalogue will be applied. ****************************** Wite puppet code in puppetServer, code is written in declarative scripting language ********************** Location for writing puppetcode is: # cd /etc/puppetlabs/code/environments/production/manifests/ # ls # vim site.pp Also get the hostname of agent which will be given as node: Go to Agent machine: # hostname ip-172-31-9-221.us-east-2.compute.internal ******************* On ServerMachine #vim site.pp --code to create file info.txt on agents node 'ip-172-31-9-221.us-east-2.compute.internal'{ file{'/info.txt': ensure => 'present', content => "file from server", } } # puppet parser validate site.pp just validate it, the agent has to pull the catalogue after 30 mins and chnages will be applied we cannot wait for 30 mins so lets go to agent machien and manually pull the catalogue On Agent machine: # puppet agent --test catalogue will be applied, file will be now on the agent # cd / # ls info.txt will be there ***************************** Lets add package and service in the site.pp again go to site.pp # vim site.pp node 'ip-172-31-9-221.us-east-2.compute.internal'{ file{'/info1.txt': ensure => 'present', content => "file from server", } package{'httpd': ensure => 'present', } service{'httpd': ensure => 'running', enable => true, } } go to AGENT machine # puppet agent --test catalogue will be applied httpd-2.4.46-1.amzn2.x86_64 will be there # rpm -qa httpd ********************************* lets parametrize the code further Selector: # vim site.pp node 'ip-172-31-9-221.us-east-2.compute.internal'{ class{'linux': } } class linux{ file{'/info1.txt': ensure => 'present', content => "file from server", } package{'httpd': ensure => 'present', } service{'httpd': ensure => 'running', enable => true, } } :wq! # puppet parser validate site.pp Go to Agent # puppet agent --test ************************************ Add parametrize the package name: SELECTORS # vim site.pp $httpdservice=$osfamily?{ 'RedHat' => 'httpd', 'Debian' => 'apache2', default => 'httpd', } node 'ip-172-31-9-221.us-east-2.compute.internal'{ class{'linux': } } class linux{ file{'/info1.txt': ensure => 'present', content => "file from server", } package{$httpdservice: ensure => 'present', } service{$httpdservice: ensure => 'running', enable => true, } } :wq! Agent # puppet agent --test ******************************************* Array Variables in code: *********************************** $httpdservice=$osfamily?{ 'RedHat' => 'httpd', 'Debian' => 'apache2', default => 'httpd', } node 'ip-172-31-9-221.us-east-2.compute.internal'{ class{'linux': } } class linux{ file{'/info1.txt': ensure => 'present', content => "file from server", } $admintools=['git','nano','screen'] package{$admintools: ensure => 'present', } package{$httpdservice: ensure => 'present', } service{$httpdservice: ensure => 'running', enable => true, } } :wq! # puppet parser validate site.pp Agent # puppet agent --test git willbe installed, nano and screen are already there # git --version # nano --version # screen --version ***************************** MODULES: ********************* We can write our own module and call it in site.pp manifests] # cd .. production] # ls we have modules production] # cd modules/ modules] # ls modules] # puppet module generate sonal-deploy press enter press enter press enter press enter press enter modules] # ls deploy will be there modules] # cd deploy/ deploy] # ls examples Gemfile manifests metadata.json Rakefile README.md spec all these subdirectories will be there and we are interested in manifests directory deploy] # cd manifests # ls init.pp will be there mainfests] vim init.pp remove the comments and add docker package and start docker service class deploy { package{'docker': ensure => 'present', } service{'docker': ensure => 'running', enable => true, } } manifests] # cd .. deploy] cd .. modules] cd.. production] ls # cd manifests # ls # vim site.pp call the class from modules directory i $httpdservice=$osfamily?{ 'RedHat' => 'httpd', 'Debian' => 'apache2', default => 'httpd', } node 'ip-172-31-9-221.us-east-2.compute.internal'{ class{'linux': } class{'deploy': } } class linux{ file{'/info1.txt': ensure => 'present', content => "file from server", } $admintools=['git','nano','screen'] package{$admintools: ensure => 'present', } package{$httpdservice: ensure => 'present', } service{$httpdservice: ensure => 'running', enable => true, } :wq! # puppet parser validate site.pp AGENT # puppet agent --test # docker --version *************************** go back to modules directory and now pull module from forge # cd .. production] # cd modules modules]# puppet module install puppetlabs-vcsrepo # ls deploy vcsrepo # cd deploy # ls # cd manifests # vim init.pp class deploy { package{'docker': ensure => 'present', } service{'docker': ensure => 'running', enable => true, } vcsrepo { '/tmp/gitrepo': ensure => present, provider => git, source => 'https://github.com/Sonal0409/dockerdemo.git', } } :wq! # puppet parser validate init.pp Agent: ******* # puppet agent --test # cd /tmp # ls # git repo will be there ********************* Lets pull another module docker to build the dockerfile and generate containers *********************** cd .. cd .. modules] # puppet module install puppetlabs-docker # ls docker will be there # cd deploy # ls # cd manifests # vim init.pp class deploy { package{'docker': ensure => 'present', } service{'docker': ensure => 'running', enable => true, } vcsrepo { '/tmp/gitrepo': ensure => present, provider => git, source => 'https://github.com/Sonal0409/dockerdemo.git', } docker::image { 'myimage:puppet': docker_file => '/tmp/gitrepo/dockerfile' } docker::run { 'c1': image => 'myimage:puppet', ports => '8080', } } :wq! # puppet parser validate init.pp Agent ********* # puppet agent --test it may fail..with ruby error.. run agian # puppet agent --test # docker images # docker ps -a Access application from web: http://18.220.30.216:32768/sample/ ************************************** |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |