Commit f50de7c5 by John Donnal

updated puppet to split wattsworth and nilm

parent 0aa69cae
*~
docs/_build/*
.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
source set_locale.sh
# install the puppet forge modules
mkdir -p forge_modules
r10k puppetfile install --moduledir=./forge_modules
# 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
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
dpkg -i puppet-release-bionic.deb
add-apt-repository universe
apt-get update
apt install puppet-agent git -y
/opt/puppetlabs/bin/puppet apply --verbose --modulepath=./modules site.pp
apt install puppet-agent git r10k -y
# create the ubuntu user for the livecd
adduser ubuntu --quiet --disabled-password --gecos ""
echo -e 'ubuntu\nubuntu\n' | passwd ubuntu
adduser ubuntu sudo
adduser ubuntu dialout
#adduser ubuntu --quiet --disabled-password --gecos ""
#echo -e 'ubuntu\nubuntu\n' | passwd ubuntu
#adduser ubuntu sudo
#adduser ubuntu dialout
......@@ -38,7 +38,10 @@ class apache {
refreshonly => true,
notify => Exec['apache2ctl restart']
}
file { '/etc/apache2/sites-enabled/000-default.conf':
ensure => absent,
notify => Exec['apache2ctl restart']
}
exec{'enable-rewrite-engine':
command => '/usr/sbin/a2enmod rewrite',
require => Package[$deps],
......
......@@ -3,7 +3,9 @@
# Packages required by multiple modules
#
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:
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 @@
class joule {
require python
require common
require timescaledb
$pip_url='https://pypi.wattsworth.net/'
$pip_cmd="pip3 install --upgrade --extra-index-url ${pip_url}"
$pip_cmd="pip3 install --upgrade"
exec{'install_joule':
command => "${pip_cmd} joule",
timeout => 0,
path => ['/usr/local/bin','/usr/bin'],
}
$dsn = 'joule:joule@localhost:5432/joule'
exec{'initialize_joule':
command => 'joule initialize',
command => "joule initialize --dsn=${dsn}",
path => ['/usr/local/bin','/usr/sbin','/bin'],
creates => '/etc/joule/main.conf',
require => Exec['install_joule']
require => Exec['install_joule',
'initialize_timescale',
'initialize_schemas']
}
user{'joule':
ensure => present,
system => true
}
file{'/opt/data/joule':
ensure => directory,
owner => joule,
group => joule,
require => User['joule']
}
vcsrepo{'/etc/skel/Desktop/example_modules':
ensure => latest,
provider => git,
......@@ -51,7 +48,35 @@ class joule {
postgresql::server::db { '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 @@
# Install and bootstrap the rails api
#
class rails_api {
require nilmdb
require timescaledb
$deps = ['ruby-dev','libsqlite3-dev','nodejs', 'libpq-dev']
package {$deps:,
ensure => present
......@@ -20,12 +20,33 @@ class rails_api {
provider => git,
source => 'https://git.wattsworth.net/wattsworth/control-api.git',
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'
}
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':
ensure => present,
ensure => "1.17.2",
provider => gem,
require => Package[$deps]
}
......@@ -33,37 +54,30 @@ class rails_api {
exec {'bundle_install':
command => 'bundle install --without test development --path vendor/bundle',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
refreshonly => true,
user => 'rails',
timeout => 0,
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
exec {'db_migrate':
command => 'bundle exec rake db:migrate',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails',
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':
command => 'bundle exec rake local:bootstrap',
cwd => '/opt/api',
environment => ['RAILS_ENV=local'],
environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails',
refreshonly => true,
......
<% require 'securerandom' %>
production:
secret_key_base: <%= SecureRandom.hex(64) %>
\ No newline at end of file
......@@ -13,7 +13,7 @@ ServerName wattsworth.localhost
<Location /api>
PassengerBaseURI /api
PassengerAppRoot /opt/api
RailsEnv local
RailsEnv production
</Location>
<Directory /var/www/frontend>
......
#! /bin/bash
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
......@@ -2,6 +2,9 @@
node 'default' {
include timescaledb
include joule
include static_sites
include rails_api
include joule_labjack
}
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