diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..d019e42 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,23 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +Vagrant.configure('2') do |config| + config.vm.box = 'centos/7' + config.vm.define 'server' do |server| + server.vm.hostname = 'master' + server.vm.network 'private_network', ip: '192.168.100.100' + server.vm.provider 'virtualbox' do |vb| + vb.customize ["modifyvm", :id, "--memory", "4096"] + vb.customize ["modifyvm", :id, "--cpus", "2"] + end + server.vm.provision :shell, path: "server.sh" + end + + config.vm.define 'agent' do |agent| + agent.vm.hostname = 'agent' + agent.vm.network 'private_network', ip: '192.168.100.101' + agent.vm.provider 'virtualbox' do |vb| + vb.customize ["modifyvm", :id, "--memory", "2048"] + end + agent.vm.provision :shell, path: "agent.sh" + end +end diff --git a/agent.sh b/agent.sh new file mode 100644 index 0000000..de482db --- /dev/null +++ b/agent.sh @@ -0,0 +1,9 @@ +systemctl stop firewalld +systemctl disable firewalld +/bin/cp /vagrant/hosts /etc/ +yum install -y https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm +yum install -y puppet-agent +/bin/cp /vagrant/puppet.conf.client /etc/puppetlabs/puppet/puppet.conf +source ~/.bashrc +systemctl restart network +#puppet agent -t diff --git a/puppet.conf.client b/puppet.conf.client new file mode 100644 index 0000000..1d7bc98 --- /dev/null +++ b/puppet.conf.client @@ -0,0 +1,5 @@ +[main] +certname = agent +server = master +environment = prod +runinterval = 3m diff --git a/puppet.conf.server b/puppet.conf.server new file mode 100644 index 0000000..6573856 --- /dev/null +++ b/puppet.conf.server @@ -0,0 +1,19 @@ +# This file can be used to override the default puppet settings. +# See the following links for more details on what settings are available: +# - https://docs.puppetlabs.com/puppet/latest/reference/config_important_settings.html +# - https://docs.puppetlabs.com/puppet/latest/reference/config_about_settings.html +# - https://docs.puppetlabs.com/puppet/latest/reference/config_file_main.html +# - https://docs.puppetlabs.com/puppet/latest/reference/configuration.html +[main] +certname = master +server = master +environment = production +runinterval = 1h +strict_variables = true + +[master] +vardir = /opt/puppetlabs/server/data/puppetserver +logdir = /var/log/puppetlabs/puppetserver +rundir = /var/run/puppetlabs/puppetserver +pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid +codedir = /etc/puppetlabs/code diff --git a/server.sh b/server.sh new file mode 100644 index 0000000..fdb6bc3 --- /dev/null +++ b/server.sh @@ -0,0 +1,28 @@ +systemctl stop firewalld + systemctl disable firewalld + /bin/cp /vagrant/hosts /etc/ + yum install -y https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm + yum install -y http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-redhat94-9.4-2.noarch.rpm + yum install -y puppetserver + systemctl enable puppetserver + /bin/cp /vagrant/site.pp /etc/puppetlabs/code/environments/production/manifests + /bin/cp /vagrant/autosign.conf /etc/puppetlabs/puppet/ + /bin/cp /vagrant/puppet.conf.server /etc/puppetlabs/puppet/puppet.conf + mkdir -p /etc/puppetlabs/code/environments/prod/{manifests,modules} + /bin/cp /vagrant/site.pp.prod /etc/puppetlabs/code/environments/prod/manifests/site.pp + systemctl restart puppetserver + source ~/.bashrc + yum install postgresql94-server postgresql94-contrib -y + /usr/pgsql-9.4/bin/postgresql94-setup initdb + yes | cp /vagrant/pg_hba.conf /var/lib/pgsql/9.4/data/ + systemctl enable postgresql-9.4.service + systemctl start postgresql-9.4.service + cd / + sudo -u postgres psql -c "create user puppetdb password 'puppetdb'" + sudo -u postgres psql -c "create database puppetdb owner puppetdb" + puppet module install puppetlabs-puppetdb --version 5.1.2 + puppet module install puppetlabs-mysql --version 3.10.0 --environment prod + puppet module install puppetlabs-apache --version 1.11.0 + puppet module install spotify-puppetexplorer --version 1.1.1 + puppet module install puppet-nginx --version 0.6.0 --environment prod + systemctl restart network diff --git a/site.pp b/site.pp new file mode 100644 index 0000000..e8ba59b --- /dev/null +++ b/site.pp @@ -0,0 +1,39 @@ +# node definitions.) + +## Active Configurations ## + +# Disable filebucket by default for all File resources: +File { backup => false } + +# DEFAULT NODE +# Node definitions in this file are merged with node data from the console. See +# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on +# node definitions. + +# The default node definition matches any node lacking a more specific node +# definition. If there are no other nodes in this file, classes declared here +# will be included in every node's catalog, *in addition* to any classes +# specified in the console for that node. + +node default { + # This is where you can declare classes for all nodes. + # Example: + # class { 'my_class': } + notify { "Node ${::fqdn} is up and running!": } +} + +node 'master' { + # Configure puppetdb + class { 'puppetdb::server': + database_host => '127.0.0.1', + confdir => '/etc/puppetlabs/puppetdb/conf.d', + } + # Configure the Puppet master to use puppetdb + class { 'puppetdb::master::config': } + class { 'puppetexplorer': + vhost_options => { + rewrites => [ { rewrite_rule => [ + '^/api/metrics/v1/mbeans/puppetlabs.puppetdb.query.population:type=default,name=(.*)$ https://%{HTTP_HOST}/api/metrics/v1/mbeans/puppetlabs.puppetdb.population:name=$1 [R=301,L]' + ] } ] } + } +} \ No newline at end of file diff --git a/site.pp.prod b/site.pp.prod new file mode 100644 index 0000000..bde0b3a --- /dev/null +++ b/site.pp.prod @@ -0,0 +1,48 @@ +# node definitions.) + +## Active Configurations ## + +# Disable filebucket by default for all File resources: +File { backup => false } + +# DEFAULT NODE +# Node definitions in this file are merged with node data from the console. See +# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on +# node definitions. + +# The default node definition matches any node lacking a more specific node +# definition. If there are no other nodes in this file, classes declared here +# will be included in every node's catalog, *in addition* to any classes +# specified in the console for that node. + +node default { + # This is where you can declare classes for all nodes. + # Example: + # class { 'my_class': } + notify { "Node ${::fqdn} is up and running!": } +} + +node 'agent' { + class { 'nginx': } + class { '::mysql::server': + root_password => 'root_pass', + } + + mysql_database { 'prod_mdb': + ensure => present, + charset => 'utf8', + } + + mysql_user { 'prod_user@localhost': + ensure => present, + password_hash => mysql_password('prod_pass'), + } + + mysql_grant { 'prod_user@localhost/prod_mdb.*': + ensure => present, + options => ['GRANT'], + privileges => ['ALL'], + table => 'prod_mdb.*', + user => 'prod_user@localhost', + } +} \ No newline at end of file