Puppet:- httpd deploy
Web server (httpd) deployment through puppet
On server, create a module http
[root@pserver manifests]# pwd
/etc/puppet/manifests
[root@pserver manifests]# cd ../modules/
[root@pserver modules]# ls
httpd samba
[root@pserver modules]# cd httpd/
[root@pserver httpd]# ls
files manifests
[root@pserver httpd]# cd files/
[root@pserver files]# ls
httpd.conf index.html
[root@pserver files]# pwd
/etc/puppet/modules/httpd/files
[root@pserver files]# cd ../manifests/
[root@pserver manifests]# ls
init.pp
[root@pserver manifests]# cat init.pp
class httpd {
package {'httpd':
ensure => present,
before => Service['httpd'],
}
file {'conffile':
ensure => file,
path => '/etc/httpd/conf.d/httpd.conf',
#source => '/etc/puppet/modules/httpd/files/httpd.conf',
source => "puppet:///modules/httpd/httpd.conf",
require => Package['httpd'],
notify => Service['httpd'],
}
file{'htmlfile':
ensure => file,
path => '/var/www/html/index.html',
source => 'puppet:///modules/httpd/index.html',
require => Package['httpd'],
}
service {'httpd':
ensure => running,
enable => true,
}
}
[root@pserver manifests]# pwd
/etc/puppet/modules/httpd/manifests
[root@pserver manifests]# more /etc/puppet/puppet.conf
[main]
certname=pserver.example.com
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
[root@pserver manifests]#
[root@pserver manifests]# cd /etc/puppet/manifests
[root@pserver manifests]# cat site.pp
include httpd
[root@pserver httpd]# ls
files manifests
[root@pserver httpd]# cd files
[root@pserver files]# ls
httpd.conf index.html
[root@pserver files]# cat index.html
<h1> This is my puppet test file. </h1>
[root@pserver files]# cat httpd.conf
<virtualhost *:80>
servername pserver.example.com
DocumentRoot /var/www/html
</virtualhost>
[root@pserver files]#
Now, go to agent and run the puppet agent -t command
[root@node1 ~]# rpm -qa | grep -i htpd
[root@node1 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node1.example.com
Info: Applying configuration version '1511743302'
Notice: /Stage[main]/Httpd/Package[httpd]/ensure: created
Notice: /Stage[main]/Httpd/File[htmlfile]/content:
--- /var/www/html/index.html 2017-11-25 18:29:08.961053523 -0500
+++ /tmp/puppet-file20171126-14861-1bq6tj0 2017-11-26 19:41:44.797668250 -0500
@@ -1 +1 @@
-<h1>This is my puppet test.</h1>
+<h1> This is my puppet test file. </h1>
Info: Computing checksum on file /var/www/html/index.html
Info: /Stage[main]/Httpd/File[htmlfile]: Filebucketed /var/www/html/index.html to puppet with sum 4e50ac7cea7d16f3e5dfd938e9f5bd23
Notice: /Stage[main]/Httpd/File[htmlfile]/content: content changed '{md5}4e50ac7cea7d16f3e5dfd938e9f5bd23' to '{md5}f2afaa35c9d79f70c0c8569e3ad50bcc'
Notice: /Stage[main]/Httpd/File[conffile]/content:
--- /etc/httpd/conf.d/httpd.conf 2017-11-25 18:29:08.996053335 -0500
+++ /tmp/puppet-file20171126-14861-1vw56pm 2017-11-26 19:41:45.017667181 -0500
@@ -1,4 +1,4 @@
-<VirtualHost *:80>
-Servername pserver.example.com
+<virtualhost *:80>
+servername pserver.example.com
DocumentRoot /var/www/html
-</VirtualHost>
+</virtualhost>
Info: Computing checksum on file /etc/httpd/conf.d/httpd.conf
Info: /Stage[main]/Httpd/File[conffile]: Filebucketed /etc/httpd/conf.d/httpd.conf to puppet with sum 1c286cf8c917e3966fdb2f7aa1936be1
Notice: /Stage[main]/Httpd/File[conffile]/content: content changed '{md5}1c286cf8c917e3966fdb2f7aa1936be1' to '{md5}8696bcdea55fdfd6036af2730cc538aa'
Info: /Stage[main]/Httpd/File[conffile]: Scheduling refresh of Service[httpd]
Notice: /Stage[main]/Httpd/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Httpd/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Finished catalog run in 2.97 seconds
[root@node1 ~]# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Sun 2017-11-26 19:41:45 EST; 11s ago
Main PID: 15046 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─15046 /usr/sbin/httpd -DFOREGROUND
├─15047 /usr/sbin/httpd -DFOREGROUND
├─15048 /usr/sbin/httpd -DFOREGROUND
├─15049 /usr/sbin/httpd -DFOREGROUND
├─15050 /usr/sbin/httpd -DFOREGROUND
└─15051 /usr/sbin/httpd -DFOREGROUND
Nov 26 19:41:45 node1.example.com systemd[1]: Started The Apache HTTP Server.
[root@node1 ~]#
On server, create a module http
[root@pserver manifests]# pwd
/etc/puppet/manifests
[root@pserver manifests]# cd ../modules/
[root@pserver modules]# ls
httpd samba
[root@pserver modules]# cd httpd/
[root@pserver httpd]# ls
files manifests
[root@pserver httpd]# cd files/
[root@pserver files]# ls
httpd.conf index.html
[root@pserver files]# pwd
/etc/puppet/modules/httpd/files
[root@pserver files]# cd ../manifests/
[root@pserver manifests]# ls
init.pp
[root@pserver manifests]# cat init.pp
class httpd {
package {'httpd':
ensure => present,
before => Service['httpd'],
}
file {'conffile':
ensure => file,
path => '/etc/httpd/conf.d/httpd.conf',
#source => '/etc/puppet/modules/httpd/files/httpd.conf',
source => "puppet:///modules/httpd/httpd.conf",
require => Package['httpd'],
notify => Service['httpd'],
}
file{'htmlfile':
ensure => file,
path => '/var/www/html/index.html',
source => 'puppet:///modules/httpd/index.html',
require => Package['httpd'],
}
service {'httpd':
ensure => running,
enable => true,
}
}
[root@pserver manifests]# pwd
/etc/puppet/modules/httpd/manifests
[root@pserver manifests]# more /etc/puppet/puppet.conf
[main]
certname=pserver.example.com
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
[root@pserver manifests]#
[root@pserver manifests]# cd /etc/puppet/manifests
[root@pserver manifests]# cat site.pp
include httpd
[root@pserver httpd]# ls
files manifests
[root@pserver httpd]# cd files
[root@pserver files]# ls
httpd.conf index.html
[root@pserver files]# cat index.html
<h1> This is my puppet test file. </h1>
[root@pserver files]# cat httpd.conf
<virtualhost *:80>
servername pserver.example.com
DocumentRoot /var/www/html
</virtualhost>
[root@pserver files]#
Now, go to agent and run the puppet agent -t command
[root@node1 ~]# rpm -qa | grep -i htpd
[root@node1 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node1.example.com
Info: Applying configuration version '1511743302'
Notice: /Stage[main]/Httpd/Package[httpd]/ensure: created
Notice: /Stage[main]/Httpd/File[htmlfile]/content:
--- /var/www/html/index.html 2017-11-25 18:29:08.961053523 -0500
+++ /tmp/puppet-file20171126-14861-1bq6tj0 2017-11-26 19:41:44.797668250 -0500
@@ -1 +1 @@
-<h1>This is my puppet test.</h1>
+<h1> This is my puppet test file. </h1>
Info: Computing checksum on file /var/www/html/index.html
Info: /Stage[main]/Httpd/File[htmlfile]: Filebucketed /var/www/html/index.html to puppet with sum 4e50ac7cea7d16f3e5dfd938e9f5bd23
Notice: /Stage[main]/Httpd/File[htmlfile]/content: content changed '{md5}4e50ac7cea7d16f3e5dfd938e9f5bd23' to '{md5}f2afaa35c9d79f70c0c8569e3ad50bcc'
Notice: /Stage[main]/Httpd/File[conffile]/content:
--- /etc/httpd/conf.d/httpd.conf 2017-11-25 18:29:08.996053335 -0500
+++ /tmp/puppet-file20171126-14861-1vw56pm 2017-11-26 19:41:45.017667181 -0500
@@ -1,4 +1,4 @@
-<VirtualHost *:80>
-Servername pserver.example.com
+<virtualhost *:80>
+servername pserver.example.com
DocumentRoot /var/www/html
-</VirtualHost>
+</virtualhost>
Info: Computing checksum on file /etc/httpd/conf.d/httpd.conf
Info: /Stage[main]/Httpd/File[conffile]: Filebucketed /etc/httpd/conf.d/httpd.conf to puppet with sum 1c286cf8c917e3966fdb2f7aa1936be1
Notice: /Stage[main]/Httpd/File[conffile]/content: content changed '{md5}1c286cf8c917e3966fdb2f7aa1936be1' to '{md5}8696bcdea55fdfd6036af2730cc538aa'
Info: /Stage[main]/Httpd/File[conffile]: Scheduling refresh of Service[httpd]
Notice: /Stage[main]/Httpd/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Httpd/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Finished catalog run in 2.97 seconds
[root@node1 ~]# systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Sun 2017-11-26 19:41:45 EST; 11s ago
Main PID: 15046 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─15046 /usr/sbin/httpd -DFOREGROUND
├─15047 /usr/sbin/httpd -DFOREGROUND
├─15048 /usr/sbin/httpd -DFOREGROUND
├─15049 /usr/sbin/httpd -DFOREGROUND
├─15050 /usr/sbin/httpd -DFOREGROUND
└─15051 /usr/sbin/httpd -DFOREGROUND
Nov 26 19:41:45 node1.example.com systemd[1]: Started The Apache HTTP Server.
[root@node1 ~]#
if you want to specify specific host, edit the site.pp file under manifest.
[root@pserver manifests]# cat site.pp
node 'node1.example.com' {
include samba
}
node 'node2.example.com' {
include httpd
}
[root@pserver manifests]#
[root@pserver manifests]# cat site.pp
node 'node1.example.com' {
include samba
}
node 'node2.example.com' {
include httpd
}
[root@pserver manifests]#
No comments:
Post a Comment