Commit f50de7c5 by John Donnal

updated puppet to split wattsworth and nilm

parent 0aa69cae
*~ *~
docs/_build/* docs/_build/*
.DS_Store .DS_Store
forge_modules/
*.idea
==== Ubuntu Installation ======
1.) Create a squashfs filesystem with cubic
2.) From within cubic, run the bootstrap script
$> ./bootstrap.sh
3.) Run as a container
sudo systemd-nspawn -D wattsworth_cubic/squashfs-root/ --bind /home/jdonnal/puppet:/home/ubuntu/puppet -b --network-interface=enxd8eb97bdd8ed --bind /media/jdonnal/wattsworth_tests:/home/ubuntu/tests
4.) From inside the container run boostrap and apply scripts
5.) Test with wattsworth test script
==== Raspbian Installation ====
see:
http://blog.oddbit.com/2016/02/07/systemd-nspawn-for-fun-and-well-mostly-f/
1.) extract compressed image
2.)Expand the image to 8G--
qemu-img resize <img> 8G
echo ", +" | sfdisk -N 2 <img>
3.) create a loopback device
(-f: find first unused device, create a partitioned device, show the lo device)
losetup -fP --show <img>
4.) expand the file system
e2fsck -f /dev/loop1p2
resize2fs /dev/loop1p2
3.) mount to rpi/mnt and rpi/mnt/boot
mount /dev/loop1p2 mnt
mount /dev/loop1p1 mnt/boot
4.) copy over the qemu emulator
cp /usr/bin/qemu-arm-static mnt/usr/bin
4.) spawn a container:
systemd-nspawn -D mnt -b --network-interface enxd8eb97bdd8ed --bind /home/jdonnal/puppet:/home/pi/puppet -b --network-interface=enxd8eb97bdd8ed --bind /media/jdonnal/wattsworth_tests:/home/pi/tests -M rpi
#!/bin/bash #!/bin/bash
source set_locale.sh
# install the puppet forge modules # install the puppet forge modules
mkdir -p forge_modules mkdir -p forge_modules
r10k puppetfile install --moduledir=./forge_modules r10k puppetfile install --moduledir=./forge_modules
# run puppet # run puppet
puppet apply --modulepath=./forge_modules:./modules --verbose site.pp /opt/puppetlabs/bin/puppet apply --verbose --modulepath=./forge_modules:./modules site.pp
#!/bin/bash #!/bin/bash
set -e set -e
echo "nameserver 172.31.33.1" > /etc/resolv.conf # start a container with the following command:
# sudo systemd-nspawn -D squashfs-root/ -b --network-interface=enxd8eb97bdd8ed --bind-ro=/home/jdonnal/puppet:/home/ubuntu/puppet -M wattsworth
#echo "nameserver 172.31.33.1" > /etc/resolv.conf
apt-get update
apt-get upgrade -y
wget https://apt.puppetlabs.com/puppet-release-bionic.deb wget https://apt.puppetlabs.com/puppet-release-bionic.deb
dpkg -i puppet-release-bionic.deb dpkg -i puppet-release-bionic.deb
add-apt-repository universe add-apt-repository universe
apt-get update apt-get update
apt install puppet-agent git -y apt install puppet-agent git r10k -y
/opt/puppetlabs/bin/puppet apply --verbose --modulepath=./modules site.pp
# create the ubuntu user for the livecd # create the ubuntu user for the livecd
adduser ubuntu --quiet --disabled-password --gecos "" #adduser ubuntu --quiet --disabled-password --gecos ""
echo -e 'ubuntu\nubuntu\n' | passwd ubuntu #echo -e 'ubuntu\nubuntu\n' | passwd ubuntu
adduser ubuntu sudo #adduser ubuntu sudo
adduser ubuntu dialout #adduser ubuntu dialout
...@@ -38,7 +38,10 @@ class apache { ...@@ -38,7 +38,10 @@ class apache {
refreshonly => true, refreshonly => true,
notify => Exec['apache2ctl restart'] notify => Exec['apache2ctl restart']
} }
file { '/etc/apache2/sites-enabled/000-default.conf':
ensure => absent,
notify => Exec['apache2ctl restart']
}
exec{'enable-rewrite-engine': exec{'enable-rewrite-engine':
command => '/usr/sbin/a2enmod rewrite', command => '/usr/sbin/a2enmod rewrite',
require => Package[$deps], require => Package[$deps],
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
# Packages required by multiple modules # Packages required by multiple modules
# #
class common { class common {
$pkgs=['build-essential','screen','emacs','openvpn', 'nmap','wget', 'sqlite3', 'gparted', 'net-tools','openssh-server','chromium-browser'] $pkgs=['build-essential','screen','emacs','openvpn',
'nmap','wget', 'sqlite3', 'gparted', 'net-tools',
'openssh-server','chromium-browser','zlib1g-dev']
package { $pkgs: package { $pkgs:
ensure => present ensure => present
......
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
CREATE SCHEMA data;
CREATE SCHEMA metadata;
GRANT ALL PRIVILEGES ON data TO joule;
GRANT ALL PRIVILEGES ON metadata TO joule;
...@@ -15,33 +15,30 @@ ...@@ -15,33 +15,30 @@
class joule { class joule {
require python require python
require common require common
require timescaledb
$pip_url='https://pypi.wattsworth.net/' $pip_cmd="pip3 install --upgrade"
$pip_cmd="pip3 install --upgrade --extra-index-url ${pip_url}"
exec{'install_joule': exec{'install_joule':
command => "${pip_cmd} joule", command => "${pip_cmd} joule",
timeout => 0, timeout => 0,
path => ['/usr/local/bin','/usr/bin'], path => ['/usr/local/bin','/usr/bin'],
} }
$dsn = 'joule:joule@localhost:5432/joule'
exec{'initialize_joule': exec{'initialize_joule':
command => 'joule initialize', command => "joule initialize --dsn=${dsn}",
path => ['/usr/local/bin','/usr/sbin','/bin'], path => ['/usr/local/bin','/usr/sbin','/bin'],
creates => '/etc/joule/main.conf', creates => '/etc/joule/main.conf',
require => Exec['install_joule'] require => Exec['install_joule',
'initialize_timescale',
'initialize_schemas']
} }
user{'joule': user{'joule':
ensure => present, ensure => present,
system => true system => true
} }
file{'/opt/data/joule':
ensure => directory,
owner => joule,
group => joule,
require => User['joule']
}
vcsrepo{'/etc/skel/Desktop/example_modules': vcsrepo{'/etc/skel/Desktop/example_modules':
ensure => latest, ensure => latest,
provider => git, provider => git,
...@@ -51,7 +48,35 @@ class joule { ...@@ -51,7 +48,35 @@ class joule {
postgresql::server::db { 'joule': postgresql::server::db { 'joule':
user => 'joule', user => 'joule',
password=> postgresql_password('joule','changeme'), password=> postgresql_password('joule','joule'),
}
postgresql::server::grant_role { 'joule':
group => 'pg_read_all_settings',
ensure => 'present',
psql_db => 'joule',
require => Postgresql::Server::Db['joule']
} }
$sql_cmd = @(EOT)
CREATE SCHEMA data;
CREATE SCHEMA metadata;
GRANT ALL PRIVILEGES ON data TO joule;
GRANT ALL PRIVILEGES ON metadata TO joule;
| EOT
exec { 'initialize_schemas':
command => "echo '${sql_cmd}' | psql",
user => 'joule',
path => ['/usr/bin:/bin'],
require => Postgresql::Server::Db['joule']
}
$sql_timescale = 'CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;'
exec { 'initialize_timescale':
command => "psql joule -c '$sql_timescale'",
user => 'postgres',
path => ['/usr/bin:/bin'],
require => Postgresql::Server::Db['joule']
}
} }
production:
adapter: postgresql
database: rails
host: localhost
pool: 5
encoding: unicode
username: rails
password: rails
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
# Install and bootstrap the rails api # Install and bootstrap the rails api
# #
class rails_api { class rails_api {
require nilmdb require timescaledb
$deps = ['ruby-dev','libsqlite3-dev','nodejs', 'libpq-dev'] $deps = ['ruby-dev','libsqlite3-dev','nodejs', 'libpq-dev']
package {$deps:, package {$deps:,
ensure => present ensure => present
...@@ -20,12 +20,33 @@ class rails_api { ...@@ -20,12 +20,33 @@ class rails_api {
provider => git, provider => git,
source => 'https://git.wattsworth.net/wattsworth/control-api.git', source => 'https://git.wattsworth.net/wattsworth/control-api.git',
require => User['rails'], require => User['rails'],
notify => Exec['bundle_install','db_migrate','local_bootstrap'], notify => [Exec['bundle_install','db_migrate','local_bootstrap'], File['/opt/api/config/database.yml']],
owner => 'rails' owner => 'rails'
} }
file {'/opt/api/config/database.yml':
source => 'puppet:///modules/rails_api/database.yml',
owner => 'rails',
group => 'rails',
mode => '0644',
require => Vcsrepo['/opt/api']
}
file {'/opt/api/config/secrets.yml':
content => template('rails_api/secrets.yml.erb'),
owner => 'rails',
group => 'rails',
mode => '0644',
require => Vcsrepo['/opt/api']
}
postgresql::server::db { 'rails':
user => 'rails',
password=> postgresql_password('rails','rails'),
}
package {'bundler': package {'bundler':
ensure => present, ensure => "1.17.2",
provider => gem, provider => gem,
require => Package[$deps] require => Package[$deps]
} }
...@@ -33,37 +54,30 @@ class rails_api { ...@@ -33,37 +54,30 @@ class rails_api {
exec {'bundle_install': exec {'bundle_install':
command => 'bundle install --without test development --path vendor/bundle', command => 'bundle install --without test development --path vendor/bundle',
cwd => '/opt/api', cwd => '/opt/api',
environment => ['RAILS_ENV=local'], environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'], path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
refreshonly => true, refreshonly => true,
user => 'rails', user => 'rails',
timeout => 0, timeout => 0,
require => [Vcsrepo['/opt/api'],Package['bundler']] require => [Vcsrepo['/opt/api'],Package['bundler']]
} }
exec {'db_setup':
command => 'bundle exec rake db:setup',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
creates => '/opt/api/db/local.sqlite3',
user => 'rails',
require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['bundle_install']]
}
#migrate the database #migrate the database
exec {'db_migrate': exec {'db_migrate':
command => 'bundle exec rake db:migrate', command => 'bundle exec rake db:migrate',
cwd => '/opt/api', cwd => '/opt/api',
environment => ['RAILS_ENV=local'], environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'], path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails', user => 'rails',
refreshonly => true, refreshonly => true,
require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['db_setup']] require => [Vcsrepo['/opt/api'],Package['bundler'],Postgresql::Server::Db['rails']]
} }
#migrate the database
#create initial models in the database
exec {'local_bootstrap': exec {'local_bootstrap':
command => 'bundle exec rake local:bootstrap', command => 'bundle exec rake local:bootstrap',
cwd => '/opt/api', cwd => '/opt/api',
environment => ['RAILS_ENV=local'], environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'], path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails', user => 'rails',
refreshonly => true, refreshonly => true,
......
<% require 'securerandom' %>
production:
secret_key_base: <%= SecureRandom.hex(64) %>
\ No newline at end of file
...@@ -13,7 +13,7 @@ ServerName wattsworth.localhost ...@@ -13,7 +13,7 @@ ServerName wattsworth.localhost
<Location /api> <Location /api>
PassengerBaseURI /api PassengerBaseURI /api
PassengerAppRoot /opt/api PassengerAppRoot /opt/api
RailsEnv local RailsEnv production
</Location> </Location>
<Directory /var/www/frontend> <Directory /var/www/frontend>
......
#! /bin/bash
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
node 'default' { node 'default' {
include timescaledb include timescaledb
include joule include joule
include static_sites
include rails_api
include joule_labjack
} }
node 'nilm'{ node 'nilm'{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment