Difference between revisions of "Puppet Manifest Samples"

From Tech-Wiki
Jump to: navigation, search
(Created page with " First start creating your manifest sudo vi /etc/puppet/manifests/lamp.pp # add user user { 'mitchell': ensure => present, uid => '1000', gid => '...")
 
 
Line 1: Line 1:
 +
[[Category:Linux]]
  
 
First start creating your manifest
 
First start creating your manifest
 
  sudo vi /etc/puppet/manifests/lamp.pp
 
  sudo vi /etc/puppet/manifests/lamp.pp
 
  
 
  # add user
 
  # add user
Line 12: Line 12:
 
   home      => '/home/mitchell'
 
   home      => '/home/mitchell'
 
  }
 
  }
 
 
  # install package
 
  # install package
 
  package { 'apache2', 'mysql-server', 'php5':
 
  package { 'apache2', 'mysql-server', 'php5':
Line 18: Line 17:
 
   ensure => installed,
 
   ensure => installed,
 
  }
 
  }
 
 
 
  # new virtual host in apache
 
  # new virtual host in apache
 
  node 'host2' {
 
  node 'host2' {
Line 28: Line 25:
 
   }
 
   }
 
  }
 
  }
 
 
  # ensure service is running
 
  # ensure service is running
 
  service { 'mysql','httpd':
 
  service { 'mysql','httpd':
 
   ensure => running,
 
   ensure => running,
 
  }
 
  }
 
 
  # execute 'apt-get update'
 
  # execute 'apt-get update'
 
  exec { 'apt-update':                    # exec resource named 'apt-update'
 
  exec { 'apt-update':                    # exec resource named 'apt-update'
 
   command => '/usr/bin/apt-get update'  # command this resource will run
 
   command => '/usr/bin/apt-get update'  # command this resource will run
 
  }
 
  }
 
 
  # ensure info.php file exists
 
  # ensure info.php file exists
 
  file { '/var/www/html/info.php':
 
  file { '/var/www/html/info.php':

Latest revision as of 19:38, 1 May 2018


First start creating your manifest

sudo vi /etc/puppet/manifests/lamp.pp
# add user
user { 'mitchell':
 ensure     => present,
 uid        => '1000',
 gid        => '1000',
 shell      => '/bin/bash',
 home       => '/home/mitchell'
}
# install package
package { 'apache2', 'mysql-server', 'php5':
 require => Exec['apt-update'],        # require 'apt-update' before installing
 ensure => installed,
}
# new virtual host in apache
node 'host2' {
 class { 'apache': }             # use apache module
 apache::vhost { 'example.com':  # define vhost resource
   port    => '80',
   docroot => '/var/www/html'
 }
}
# ensure service is running
service { 'mysql','httpd':
 ensure => running,
}
# execute 'apt-get update'
exec { 'apt-update':                    # exec resource named 'apt-update'
 command => '/usr/bin/apt-get update'  # command this resource will run
}
# 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
} 


Now validate and apply

sudo puppet apply --test