Puppet näited

From ICO wiki
Jump to navigationJump to search

Sissejuhatus

rak.planet.zz

puppet.planet.zz

client.planet.zz

Puppet manifestid ja konfiguratsioon

/etc/puppet/fileserver.conf

[export]
path /var/lib/puppet/export
 allow *

/etc/puppet/manifests/site.pp

import "classes/*"

	node basenode {
		include test_class
		include rootkeys
		include userkey
		include hostnames
		package {'cowsay': ensure => latest }
	}	

	node 'client.planet.zz' inherits basenode {
		include tarkvara
		package {'git-cola': ensure => latest }
		package {'vim-puppet': ensure => latest }
		package {'mc': ensure => latest }
		package {'openjdk-7-jre': ensure => latest }
	}
	node 'rak.planet.zz' inherits basenode {
		include tarkvara
		include userid
		include gitkey
		include issue
		class { '::ntp':
 			 servers => [ 'ntp.eenet.ee', 'ntp.ut.ee' ],
		}	
		include weebiserver
		include	mysqlserver
		include dvwa
	}

/etc/puppet/manifests/classes/rak.pp

class weebiserver {

class { 'apache': }

apache::vhost { 'www.planet.zz':
      port          => '80',
      docroot       => '/var/www/www.planet.zz',
      docroot_owner => 'www-data',
      docroot_group => 'www-data',
    }

apache::vhost { 'sales.planet.zz':
      port          => '80',
      docroot       => '/var/www/sales.planet.zz',
      docroot_owner => 'www-data',
      docroot_group => 'www-data',
    }

apache::mod { 'php5': }

#file { '/var/www/www.planet.zz/':
#  ensure => 'directory',
#  group  => 'www-data',
#  mode   => '755',
#  owner  => 'www-data',
#  type   => 'directory',
#}

#file { '/var/www/sales.planet.zz/':
#  ensure => 'directory',
#  group  => 'www-data',
#  mode   => '755',
#  owner  => 'www-data',
 # type   => 'directory',
#}

file { '/var/www/www.planet.zz/index.html':
  ensure  => 'file',
  content => "${fqdn} serveerib hostinime www.planet.zz",
  group   => 'www-data',
  mode    => '644',
  owner   => 'www-data',
#  type    => 'file',
  require => File['/var/www/www.planet.zz'],
}

file { '/var/www/sales.planet.zz/index.html':
  ensure  => 'file',
  content => "${fqdn} serveerib hostinime sales.planet.zz",
  group   => 'www-data',
  mode    => '644',
  owner   => 'www-data',
  require => File['/var/www/sales.planet.zz'],
 # type    => 'file',
}

#File['/var/www/sales.planet.zz/index.html']->File['/var/www/sales.planet.zz']

}


class hostnames {
host { 'www.planet.zz':
  ensure       => 'present',
  host_aliases => ['www'],
  ip           => '192.168.56.201',
  target       => '/etc/hosts',
}

host { 'sales.planet.zz':
  ensure       => 'present',
  host_aliases => ['sales'],
  ip           => '192.168.56.201',
  target       => '/etc/hosts',
}


}

class mysqlserver {
class { '::mysql::server':
  root_password    => 'student',
  override_options => { 'mysqld' => { 'max_connections' => '1024' } }
}
mysql::db { 'dvwa':
      user     => 'dvwa',
      password => 'student',
      host     => 'localhost',
      grant    => ['ALL'],
    }
}

class dvwa {

file { '/root/DVWA-1.0.8.tar.gz':
  ensure  => 'file',
  source => 'puppet:///export/DVWA-1.0.8.tar.gz',
  group   => 'root',
  mode    => '600',
  owner   => 'root',
}

#exec ( pakib lahti ja liigutab teise kohta)
# sätib õigused paika (www-data)
# loob faili dvwa-version sisuga 1.0.8
# läheb käima ainult siis, kui dvwa-version pole õige sisuga

exec {'dvwa_install':
	cwd => '/root',
	path => ["/bin","/usr/bin"],
	subscribe   => File["/root/DVWA-1.0.8.tar.gz"],
	unless => "grep -E '^1\.0\.8$' /root/DVWA_VERSION >/dev/null",
	command => "tar zxf /root/DVWA-1.0.8.tar.gz --directory /var/www/sales.planet.zz && chown www-data:www-data /var/www/sales.planet.zz/DVWA-1.0.8/ -R && ln -sf /var/www/sales.planet.zz/DVWA-1.0.8/ /var/www/sales.planet.zz/dvwa && echo '1.0.8' > /root/DVWA_VERSION",

}
package {'php5-mysql': ensure => latest }

}