I am writing this post as part of course Linuxin keskitetty hallinta held by Tero Karvinen. In this post I will create new package-file-service module and install apache2 by puppet.

If you need to help for installing puppet I recommend you beginning training puppet here:
http://nikokiuru.com/2013/11/hello-puppet/

Otherwise, let's begin to install Apache2 by puppet!

Create new module

First create new module and init.pp file inside manifests:

$ mkdir -p modules/apache2/manifests/
$ nano modules/apache2/manifests/init.pp

And the code in init.pp:

class apache2 {
  package {"apache2":
    ensure => "installed",
  }

  service {"apache2":
    ensure => "running",
    enable => "true",
    require => Package["apache2"],
  }
}

Apply our puppet module by command:

$ puppet apply --modulepath modules/ -e 'class {"apache2":}'

Test module

We can test that Apache2 is running by command:

$ sudo service apache2 status

Result:
Apache2 is running

Source

http://docs.puppetlabs.com/learning/ordering.html#packagefileservice