This short configuration continues from below link.
http://wnapdlf.blogspot.jp/2015/04/puppet-new-node-addition.html
# Latest nginx install ubuntu 14.04 trusty and centos7.0
# I created init.pp,config.pp,ubuntu_config for installing and updating latest nginx stable version from nginx.org
# I use cat command to show *.pp and files
root@puppet:/etc/puppet/modules/nginx/manifests# cat init.pp
class nginx {
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
include nginx::config
# do something RHEL specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update'
}
exec { 'yum-nginx-pcre':
command => '/bin/yum -y install pcre-devel',
require => Exec['yum-update']
}
#install nginx ensure
package { 'nginx':
ensure => installed,
}
#running service
service { 'nginx':
ensure => running,
}
}
'ubuntu': {
#inlcude ubuntu_config is for running latest nginx version from nginx.org apt-repo
#When we do not want to install latest nginx package,just comment include line
include nginx::ubuntu_config
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
package { 'nginx':
ensure => latest,
}
# running nginx
service { 'nginx':
ensure => running,
}
}
default: {
# ...
}
}
}
root@puppet:/etc/puppet/modules/nginx/manifests# cat config.pp
# Latest nginx for centos(maybe useful for redhat)
class nginx::config {
file { "/etc/yum.repos.d/nginx.repo":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx.repo",
}
}
root@puppet:/etc/puppet/modules/nginx/manifests# cat ubuntu_config.pp
class nginx::ubuntu_config {
file { "/etc/apt/sources.list.d/nginx.list":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx.ulist",
}
file { "/tmp/nginx_signing.key":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx_signing.key",
}
exec {'key-add':
command => '/usr/bin/apt-key add /tmp/nginx_signing.key'
}
#removing ubuntu repo's nginx packages
exec {'remove-pre-nginx':
command => '/usr/bin/apt-get -y remove --purge nginx nginx-common nginx-core'
}
#$nginx_pkgs = ["nginx","nginx-common","nginx-core"]
#package { $nginx_pkgs: ensure => "absent" }
}
root@puppet:/etc/puppet/modules/nginx/manifests# cd ../files/
root@puppet:/etc/puppet/modules/nginx/files# cat nginx
nginx.repo nginx_signing.key nginx.ulist
#nginx.repo for centos7, nginx_signing.key for add-key for ubuntu, nginx.ulist is apt-repo for ubuntu trusty 14.04
root@puppet:/etc/puppet/modules/nginx/files# cat nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
root@puppet:/etc/puppet/modules/nginx/files# cat nginx.ulist
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx
# We can get nginx_signing.key from nginx.org.http://nginx.org/keys/nginx_signing.key
root@puppet:/etc/puppet/modules/nginx/files# cat nginx_signing.key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (FreeBSD)
mQENBE5OMmIBCAD+FPYKGriGGf7NqwKfWC83cBV01gabgVWQmZbMcFzeW+hMsgxH
W6iimD0RsfZ9oEbfJCPG0CRSZ7ppq5pKamYs2+EJ8Q2ysOFHHwpGrA2C8zyNAs4I
QxnZZIbETgcSwFtDun0XiqPwPZgyuXVm9PAbLZRbfBzm8wR/3SWygqZBBLdQk5TE
fDR+Eny/M1RVR4xClECONF9UBB2ejFdI1LD45APbP2hsN/piFByU1t7yK2gpFyRt
97WzGHn9MV5/TL7AmRPM4pcr3JacmtCnxXeCZ8nLqedoSuHFuhwyDnlAbu8I16O5
XRrfzhrHRJFM1JnIiGmzZi6zBvH0ItfyX6ttABEBAAG0KW5naW54IHNpZ25pbmcg
a2V5IDxzaWduaW5nLWtleUBuZ2lueC5jb20+iQE+BBMBAgAoBQJOTjJiAhsDBQkJ
ZgGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRCr9b2Ce9m/YpvjB/98uV4t
94d0oEh5XlqEZzVMrcTgPQ3BZt05N5xVuYaglv7OQtdlErMXmRWaFZEqDaMHdniC
sF63jWMd29vC4xpzIfmsLK3ce9oYo4t9o4WWqBUdf0Ff1LMz1dfLG2HDtKPfYg3C
8NESud09zuP5NohaE8Qzj/4p6rWDiRpuZ++4fnL3Dt3N6jXILwr/TM/Ma7jvaXGP
DO3kzm4dNKp5b5bn2nT2QWLPnEKxvOg5Zoej8l9+KFsUnXoWoYCkMQ2QTpZQFNwF
xwJGoAz8K3PwVPUrIL6b1lsiNovDgcgP0eDgzvwLynWKBPkRRjtgmWLoeaS9FAZV
ccXJMmANXJFuCf26iQEcBBABAgAGBQJOTkelAAoJEKZP1bF62zmo79oH/1XDb29S
YtWp+MTJTPFEwlWRiyRuDXy3wBd/BpwBRIWfWzMs1gnCjNjk0EVBVGa2grvy9Jtx
JKMd6l/PWXVucSt+U/+GO8rBkw14SdhqxaS2l14v6gyMeUrSbY3XfToGfwHC4sa/
Thn8X4jFaQ2XN5dAIzJGU1s5JA0tjEzUwCnmrKmyMlXZaoQVrmORGjCuH0I0aAFk
RS0UtnB9HPpxhGVbs24xXZQnZDNbUQeulFxS4uP3OLDBAeCHl+v4t/uotIad8v6J
SO93vc1evIje6lguE81HHmJn9noxPItvOvSMb2yPsE8mH4cJHRTFNSEhPW6ghmlf
Wa9ZwiVX5igxcvaIRgQQEQIABgUCTk5b0gAKCRDs8OkLLBcgg1G+AKCnacLb/+W6
cflirUIExgZdUJqoogCeNPVwXiHEIVqithAM1pdY/gcaQZmIRgQQEQIABgUCTk5f
YQAKCRCpN2E5pSTFPnNWAJ9gUozyiS+9jf2rJvqmJSeWuCgVRwCcCUFhXRCpQO2Y
Va3l3WuB+rgKjsQ=
=A015
-----END PGP PUBLIC KEY BLOCK-----
#puppet master site.pp contents
root@puppet:/etc/puppet/modules/nginx/files# cat /etc/puppet/manifests/site.pp
node default { }
node 'ts' {
include nginx
include ssh
}
node 'ts1' {
include nginx
include ssh
include java
}
node 'ct7' {
include nginx
}
#centos7 test
[root@ct7 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: nmcli (1.0.0) and NetworkManager (0.9.9.1) versions don't match. Force execution using --nocheck, but the results are unpredictable.
Info: Caching catalog for ct7
Info: Applying configuration version '1428636203'
Notice: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]/content:
--- /etc/yum.repos.d/nginx.repo 2015-04-10 03:21:37.022246045 +0000
+++ /tmp/puppet-file20150410-26365-megu4d 2015-04-10 03:23:23.989743092 +0000
@@ -1,5 +1,5 @@
[nginx]
name=nginx repo
-baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
+baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
Info: Computing checksum on file /etc/yum.repos.d/nginx.repo
Info: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]: Filebucketed /etc/yum.repos.d/nginx.repo to puppet with sum 5acdea38793982f7a967a49fb4ad8580
Notice: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]/content: content changed '{md5}5acdea38793982f7a967a49fb4ad8580' to '{md5}c8473d7b3b6920ac8d59ac3ae6e843e0'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: /Stage[main]/Nginx/Exec[yum-update]/returns: executed successfully
Notice: /Stage[main]/Nginx/Exec[yum-nginx-pcre]/returns: executed successfully
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]
Notice: Finished catalog run in 43.20 seconds
[root@ct7 ~]# ps -ef | grep nginx
root 26576 1 0 03:24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 26577 26576 0 03:24 ? 00:00:00 nginx: worker process
root 26581 3127 0 03:24 pts/0 00:00:00 grep --color=auto nginx
#ubuntu nginx install latest version from nginx.org
#ts1 is ubuntu14.04 trusty server
root@ts1:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts1
Info: Applying configuration version '1428640592'
Notice: /Stage[main]/Nginx::Ubuntu_config/Exec[remove-pre-nginx]/returns: executed successfully
Notice: /Stage[main]/Nginx::Ubuntu_config/Exec[key-add]/returns: executed successfully
Notice: /Stage[main]/Nginx::Ubuntu_config/File[/etc/apt/sources.list.d/nginx.list]/ensure: defined content as '{md5}e2e568e3450e66cbc1180fc1490d0faa'
Notice: /Stage[main]/Nginx/Exec[apt-update]/returns: executed successfully
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: ensure changed 'purged' to 'latest'
Notice: Finished catalog run in 29.07 seconds
No comments:
Post a Comment