Puppet with Amazon EC2 : Install LAMP with manifest ('puppet apply')
Puppet
We'll develop a manifest on a Puppet agent node, and execute it via puppet apply.
In the process, we learn how to write a manifest using the following types of resource declarations:
- exec: to execute commands, such as apt-get
- package: to install packages via apt
- service: to ensure that a service is running
- file: to ensure that certain files exist
To install puppet, please visit puppet install on ubuntu 14.04.
Let's create a new manifest:
$ sudo vi /etc/puppet/manifests/lamp.pp
Add the following lines to declare the resources that we just determined we wanted. The inline comments detail each resource declaration:
# 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 { 'php5': require => Exec['apt-update'], # require 'apt-update' before installing 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 }
Now we will use the puppet apply command to execute the manifest. On ip-172-31-25-70 node, run this:
$ sudo puppet apply /etc/puppet/manifests/lamp.pp Notice: Compiled catalog for ip-172-31-25-70.ec2.internal in environment production in 0.13 seconds Notice: /Stage[main]/Main/Exec[apt-update]/returns: executed successfully Notice: /Stage[main]/Main/Package[php5]/ensure: ensure changed 'purged' to 'present' Error: /Stage[main]/Main/Service[mysql]: Could not evaluate: Could not find init script or upstart conf file for 'mysql' Notice: /Stage[main]/Main/Package[mysql-server]/ensure: ensure changed 'purged' to 'present' Notice: /Stage[main]/Main/File[/var/www/html/info.php]/ensure: defined content as '{md5}d9c0c977ee96604e48b81d795236619a' Notice: Finished catalog run in 45.39 seconds
We need to comeback for the error in ensuring mysql service run though it seems to be running fine:
$ sudo service mysql status mysql start/running, process 6365 $ ps aux|grep mysql mysql 6365 0.0 5.3 623908 54412 ? Ssl 19:26 0:02 /usr/sbin/mysqld ubuntu 7227 0.0 0.0 10464 920 pts/0 S+ 22:26 0:00 grep --color=auto mysql
Looks like we successfully set up a lamp stack with Puppet!
Puppet
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization