Book Image

Puppet 5 Cookbook - Fourth Edition

By : Thomas Uphill
Book Image

Puppet 5 Cookbook - Fourth Edition

By: Thomas Uphill

Overview of this book

Puppet is a configuration management system that automates all your IT configurations, giving you control of managing each node. Puppet 5 Cookbook will take you through Puppet's latest and most advanced features, including Docker containers, Hiera, and AWS Cloud Orchestration. Updated with the latest advancements and best practices, this book delves into various aspects of writing good Puppet code, which includes using Puppet community style, checking your manifests with puppet-lint, and learning community best practices with an emphasis on real-world implementation. You will learn to set up, install, and create your first manifests with version control, and also learn about various sysadmin tasks, including managing configuration files, using Augeas, and generating files from snippets and templates. As the book progresses, you'll explore virtual resources and use Puppet's resource scheduling and auditing features. In the concluding chapters, you'll walk through managing applications and writing your own resource types, providers, and external node classifiers. By the end of this book, you will have learned to report, log, and debug your system.
Table of Contents (16 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Creating Apache virtual hosts


Apache virtual hosts are created with the apache module with the apache::vhost defined type. We will create a new vhost on our Apache webserver called navajo, after one of the Apache tribes. 

How to do it...

Follow these steps to create Apache virtual hosts:

  1. Create a navajo apache::vhost definition as follows:
apache::vhost { 'navajo.example.com':
  port => '80',
  docroot => '/var/www/navajo',
}
  1. Create an index file for the new vhost:
$navajo = @(NAVAJO)
  <html>
    <head>
      <title>navajo.example.com</title>
    </head>
    <body>http://en.wikipedia. org/wiki/Navajo_people
    </body>
  </html>
  | NAVAJO
file {'/var/www/navajo/index.html':
  content => $navajo,
  mode => '0644',
  require => Apache::Vhost['navajo.example.com']
}
  1. Run Puppet to create the new vhost:
[root@webserver ~]# puppet agent -t
Info: Caching catalog for webserver.example.com
...
Notice: /Stage[main]/Main/Node[webserver]/Apache...