From c62a79351ba95c34b44d7782ce1f266af197c786 Mon Sep 17 00:00:00 2001 From: mnikolayev Date: Wed, 19 Apr 2017 06:44:49 +0300 Subject: [PATCH] done --- README.md | 2 +- Vagrantfile | 33 +++++++++++++++++++++++++++++++ agent.sh | 9 +++++++++ autosign.conf | 1 + client_puppet.conf | 5 +++++ hosts | 4 ++++ install.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++ install.sh.txt | 47 +++++++++++++++++++++++++++++++++++++++++++++ pg_hba.conf | 3 +++ prod_site.pp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ server_puppet.conf | 19 ++++++++++++++++++ site.pp | 39 +++++++++++++++++++++++++++++++++++++ 12 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 Vagrantfile create mode 100644 agent.sh create mode 100644 autosign.conf create mode 100644 client_puppet.conf create mode 100644 hosts create mode 100644 install.sh create mode 100644 install.sh.txt create mode 100644 pg_hba.conf create mode 100644 prod_site.pp create mode 100644 server_puppet.conf create mode 100644 site.pp diff --git a/README.md b/README.md index 6f000ce..9c91617 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# lesson13 \ No newline at end of file +# puppet_hw_setup diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..52eb137 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,33 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure('2') do |config| + # define box to use + config.vm.box = "centos/7" + + # define puppet master server + config.vm.define 'server' do |server| + server.vm.hostname = 'server.m' + server.vm.network 'private_network', ip: '192.0.0.100' + server.vm.provider 'virtualbox' do |v| + v.name = 'server' + v.memory = 4096 + v.cpus = 2 + v.linked_clone = true + end + server.vm.provision :shell, path: "install.sh" + end + + # define puppet client vm + config.vm.define 'client' do |client| + client.vm.hostname = 'client.m' + client.vm.network 'private_network', ip: '192.0.0.105' + client.vm.provider 'virtualbox' do |v| + v.name = 'client' + v.memory = 1024 + v.cpus = 1 + v.linked_clone = true + end + client.vm.provision :shell, path: "agent.sh" + end +end diff --git a/agent.sh b/agent.sh new file mode 100644 index 0000000..d8b26db --- /dev/null +++ b/agent.sh @@ -0,0 +1,9 @@ + nmcli connection reload + systemctl restart network.service + grep server.m /etc/hosts + [ $? -ne 0 ] && echo "192.0.0.100 server.m" >> /etc/hosts + yum install -y https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm + yum install -y puppet-agent + /bin/cp /vagrant/client_puppet.conf /etc/puppetlabs/puppet/puppet.conf + source ~/.bashrc + puppet agent --test \ No newline at end of file diff --git a/autosign.conf b/autosign.conf new file mode 100644 index 0000000..ea9af3a --- /dev/null +++ b/autosign.conf @@ -0,0 +1 @@ +*.m \ No newline at end of file diff --git a/client_puppet.conf b/client_puppet.conf new file mode 100644 index 0000000..7833bd9 --- /dev/null +++ b/client_puppet.conf @@ -0,0 +1,5 @@ +[main] +certname = client.m +server = server.m +environment = prod +runinterval = 3m diff --git a/hosts b/hosts new file mode 100644 index 0000000..62c6732 --- /dev/null +++ b/hosts @@ -0,0 +1,4 @@ +127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 +::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 +192.0.0.100 server.m +192.0.0.105 client.m \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..e9e32ab --- /dev/null +++ b/install.sh @@ -0,0 +1,47 @@ + ######## after vm provisioning there is possibility that ip address that was specified in vagrant file + ######## won't be there after provisioning is over, restart of network service fixes it + nmcli connection reload + systemctl restart network.service + grep client.m /etc/hosts + [ $? -ne 0 ] && echo "192.0.0.105 client.m" >> /etc/hosts + ######## ям инсталл епта + 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 + ######## copying files from rsync'ed folder to their destination + /bin/cp /vagrant/hosts /etc/ + /bin/cp /vagrant/site.pp /etc/puppetlabs/code/environments/production/manifests + /bin/cp /vagrant/autosign.conf /etc/puppetlabs/puppet/ + /bin/cp /vagrant/server_puppet.conf /etc/puppetlabs/puppet/puppet.conf + ######## create folders for environments and copy manifest + mkdir -p /etc/puppetlabs/code/environments/prod/{manifests,modules} + /bin/cp /vagrant/prod_site.pp /etc/puppetlabs/code/environments/prod/manifests/site.pp + ######## reload puppet + systemctl restart puppetserver + source ~/.bashrc + ######## install postgres + yum install postgresql94-server postgresql94-contrib -y + ######## create initial db and copy configs + /usr/pgsql-9.4/bin/postgresql94-setup initdb + yes | /bin/cp /vagrant/pg_hba.conf /var/lib/pgsql/9.4/data/ + ######## enable and start postgres + systemctl enable postgresql-9.4.service + systemctl start postgresql-9.4.service + ######## change directory because of stupid error when executing as postgres + cd / + ######## create user and db in postgres + sudo -u postgres psql -c "create user puppetdb password 'puppetdb'" + sudo -u postgres psql -c "create database puppetdb owner puppetdb" + ######## installing modules in puppet and specifying production env's for them + 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 + ######## lauch and test + puppet agent -t + ######## stop iptables and add rule to selinux to passthrough httpd + systemctl stop iptables + puppet cert list --all + setsebool -P httpd_can_network_connect on \ No newline at end of file diff --git a/install.sh.txt b/install.sh.txt new file mode 100644 index 0000000..809c65e --- /dev/null +++ b/install.sh.txt @@ -0,0 +1,47 @@ + ######## after vm provisioning there is possibility that ip address that was specified in vagrant file + ######## won't be there after provisioning is over, restart of network service fixes it + nmcli connection reload + systemctl restart network.service + grep client.m /etc/hosts + [ $? -ne 0 ] && echo "192.0.0.105 client.m" >> /etc/hosts + ######## ям инсталл епта + 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 + ######## copying files from rsync'ed folder to their destination + /bin/cp /vagrant/hosts /etc/ + /bin/cp /vagrant/site.pp /etc/puppetlabs/code/environments/production/manifests + /bin/cp /vagrant/autosign.conf /etc/puppetlabs/puppet/ + /bin/cp /vagrant/server_puppet.conf /etc/puppetlabs/puppet/puppet.conf + ######## create folders for environments and copy manifest + mkdir -p /etc/puppetlabs/code/environments/prod/{manifests,modules} + /bin/cp /vagrant/prod_site.pp /etc/puppetlabs/code/environments/prod/manifests/site.pp + ######## reload puppet + systemctl restart puppetserver + source ~/.bashrc + ######## install postgres + yum install postgresql94-server postgresql94-contrib -y + ######## create initial db and copy configs + /usr/pgsql-9.4/bin/postgresql94-setup initdb + yes | /bin/cp /vagrant/pg_hba.conf /var/lib/pgsql/9.4/data/ + ######## enable and start postgres + systemctl enable postgresql-9.4.service + systemctl start postgresql-9.4.service + ######## change directory because of stupid error when executing as postgres + cd / + ######## create user and db in postgres + sudo -u postgres psql -c "create user puppetdb password 'puppetdb'" + sudo -u postgres psql -c "create database puppetdb owner puppetdb" + ######## installing modules in puppet and specifying production env's for them + 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 + ######## lauch and test + puppet agent -t + ######## stop iptables and add rule to selinux to passthrough httpd + systemctl stop iptables + setsebool -P httpd_can_network_connect on + puppet cert list --all \ No newline at end of file diff --git a/pg_hba.conf b/pg_hba.conf new file mode 100644 index 0000000..2ab4f05 --- /dev/null +++ b/pg_hba.conf @@ -0,0 +1,3 @@ +local all all peer +host all all 127.0.0.1/32 md5 +host all all ::1/128 md5 diff --git a/prod_site.pp b/prod_site.pp new file mode 100644 index 0000000..3aebe74 --- /dev/null +++ b/prod_site.pp @@ -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 'client.m' { + class { 'nginx': } + class { '::mysql::server': + root_password => 'password', + } + + mysql_database { 'prod_mdb': + ensure => present, + charset => 'utf8', + } + + mysql_user { 'prod_user@localhost': + ensure => present, + password_hash => mysql_password('prod_password'), + } + + 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 diff --git a/server_puppet.conf b/server_puppet.conf new file mode 100644 index 0000000..7d55757 --- /dev/null +++ b/server_puppet.conf @@ -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 = server.m +server = server.m +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 \ No newline at end of file diff --git a/site.pp b/site.pp new file mode 100644 index 0000000..3113bc2 --- /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 'server.m' { + # # 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