I had already done the apache2 so I mainly followed the script written in the class. I started by creating folders for sshd module, located in /etc/puppet/modules/
First I created main module folder named sshd and then two directories under sshd folder:
$ mkdir sshd; cd sshd
$ mkdir manifests/ templates/
Then I updated repositories and installed openssh-server
$ sudo apt-get update && sudo apt-get -y install openssh-server
After that I copied the sshd_config file to sshd/templates/sshd_config.erb
$ cp /etc/ssh/sshd_config templates/
Rename copied file to .erb and go to the manifests folder. There create new manifest
$ nano init.pp
Text to init.pp:
class sshd {
package { 'openssh-server':
ensure => installed,
}
service {'ssh':
ensure => running,
require => Package["openssh-server"],
}
file {'/etc/ssh/sshd_config':
ensure => file,
content => template ("/etc/puppet/modules/sshd/templates/sshd_config.erb"),
require => Package["openssh-server"],
notify => Service["ssh"],
}
}
# In this case the template path should be sshd/sshd_config.erb
Notify that my template file is in /etc/puppet/modules/sshd/templates/sshd_config.erb
And to run the module:
$ sudo puppet apply -e "include sshd"
This seems to work.
Then the apache2 module:
Same folder hierarchy for apache2, under main folder manifests folder and templates if wanted.
In the init.pp
class apache2 {
package { 'apache2':
ensure => installed,
}
service {'apache2':
ensure => running,
require => Package["apache2"],
}
file { '/var/www/testsite':
ensure => directory,
mode => 644,
require => Package["apache2"],
notify => Service["apache2"],
}
}
Text to init.pp:
class sshd {
package { 'openssh-server':
ensure => installed,
}
service {'ssh':
ensure => running,
require => Package["openssh-server"],
}
file {'/etc/ssh/sshd_config':
ensure => file,
content => template ("/etc/puppet/modules/sshd/templates/sshd_config.erb"),
require => Package["openssh-server"],
notify => Service["ssh"],
}
}
# In this case the template path should be sshd/sshd_config.erb
Notify that my template file is in /etc/puppet/modules/sshd/templates/sshd_config.erb
And to run the module:
$ sudo puppet apply -e "include sshd"
This seems to work.
Then the apache2 module:
Same folder hierarchy for apache2, under main folder manifests folder and templates if wanted.
In the init.pp
class apache2 {
package { 'apache2':
ensure => installed,
}
service {'apache2':
ensure => running,
require => Package["apache2"],
}
file { '/var/www/testsite':
ensure => directory,
mode => 644,
require => Package["apache2"],
notify => Service["apache2"],
}
}
I had already installed apache2 so I turned it off
$ sudo service apache2 stop
And run my apache2 module:
$ sudo puppet apply -e "include apache2"
As we can see apache2 is not running in the center and after I run the module apache2 is running.
And now to combine the two modules together:
$ sudo puppet apply -e "include apache2, sshd"
Test scenario if this is working:
$ sudo service apache2 stop
$ sudo service ssh top
And if we want to see what happened:
$ sudo service apache2 status / ssh status
And after the puppet run we can see it changed both services to run
Worked. And to see how the directory hierarchy is set I installed "tree"
$ sudo apt-get install tree
headed to modules folder and
$ tree
This post was home assignment for Puppet course: http://terokarvinen.com/
Ei kommentteja:
Lähetä kommentti