Lets, move one step ahead and clean up site.pp and follow a hierarchy in which resources should be setup, which is necessary, working with puppet.
/etc/puppet contains two important directories manifests and modules.
Puppet
Manifests
Modules
Edit file /etc/puppet/manifests/site.pp
Create directory /etc/puppet/manifests/nodes and create files with respective node name prefix in the nodes directory, in our case
server.puppet.com - server.pp
client1.puppet.com - client1.pp
client2.puppet.com - client2.pp
Edit file /etc/puppet/manifests/nodes/server.pp
Edit file /etc/puppet/manifests/nodes/client1.pp
Edit file /etc/puppet/manifests/nodes/client2.pp
Now, lets create modules for the packages to be installed on the clients.
Remember, we used nmap in our previous post, lets take it again.
Change to directory /etc/puppet/modules
create directory with package name to be installed on clients, create a sub directory with name as manifests in the package directory.
Modules
Next, we will create a init.pp file. The puppet autoloader convention require all modules contain an init.pp file that contains a class or define that matches the module name.
Create and edit file /etc/puppet/modules/nmap/manifests/init.pp
Now, lets get back to main manifests directory having nodes and include package class.
Edit file /etc/puppet/manifests/nodes/client2.pp
Before, applying changes lets create simple bash scripts for master and clients to apply and fetch changes respectively.
On master server : CentOS
Create and edit file - /usr/bin/papply
On client server :Ubuntu
Create and edit file - /usr/bin/pagent
On master server : CentOS
On client server :Ubuntu
/etc/puppet contains two important directories manifests and modules.
Puppet
. |-- auth.conf |-- fileserver.conf |-- manifests | |-- nodes | | |-- client1.pp | | |-- client2.pp | | `-- server.pp | `-- site.pp |-- modules | |-- accounts | | `-- manifests | | |-- init.pp | | `-- system.pp | |-- elinks | | `-- manifests | | `-- init.pp | |-- nmap | | `-- manifests | | `-- init.pp | `-- s3cmd | `-- manifests | `-- init.pp `-- puppet.conf
Manifests
manifests | |-- nodes | | |-- client1.pp | | |-- client2.pp | | `-- server.pp | `-- site.pp
Modules
modules | |-- accounts | | `-- manifests | | |-- init.pp | | `-- system.pp | |-- elinks | | `-- manifests | | `-- init.pp | |-- nmap | | `-- manifests | | `-- init.pp | `-- s3cmd | `-- manifests | `-- init.pp
Edit file /etc/puppet/manifests/site.pp
import 'nodes/*.pp'
Create directory /etc/puppet/manifests/nodes and create files with respective node name prefix in the nodes directory, in our case
server.puppet.com - server.pp
client1.puppet.com - client1.pp
client2.puppet.com - client2.pp
Edit file /etc/puppet/manifests/nodes/server.pp
node 'server.puppet.com' {
}
Edit file /etc/puppet/manifests/nodes/client1.pp
node 'client1.puppet.com' {
}
Edit file /etc/puppet/manifests/nodes/client2.pp
node 'client2.puppet.com' {
}
Now, lets create modules for the packages to be installed on the clients.
Remember, we used nmap in our previous post, lets take it again.
Change to directory /etc/puppet/modules
create directory with package name to be installed on clients, create a sub directory with name as manifests in the package directory.
Modules
|-- nmap
| `-- manifests
Next, we will create a init.pp file. The puppet autoloader convention require all modules contain an init.pp file that contains a class or define that matches the module name.
Create and edit file /etc/puppet/modules/nmap/manifests/init.pp
class nmap { case $operatingsystem { centos, redhat: { package { "nmap": ensure => installed, } } debian, ubuntu: { package { "nmap": ensure => installed, } } } }
Now, lets get back to main manifests directory having nodes and include package class.
Edit file /etc/puppet/manifests/nodes/client2.pp
node 'client2.puppet.com' {
include nmap
}
Before, applying changes lets create simple bash scripts for master and clients to apply and fetch changes respectively.
On master server : CentOS
Create and edit file - /usr/bin/papply
#!/bin/bash
/usr/bin/puppet apply -v /etc/puppet/manifests/site.pp
On client server :Ubuntu
Create and edit file - /usr/bin/pagent
#!/bin/bash
/usr/bin/puppet agent -v --test
On master server : CentOS
papply Notice: Finished catalog run in 0.07 seconds
On client server :Ubuntu
pagent Info: Retrieving plugin Info: Caching catalog for client2.puppet.com Info: Applying configuration version '1390207277' Notice: Finished catalog run in 0.41 seconds
No comments:
Post a Comment