RVM installing but no Rubies with Chef-solo and Vagrant? - vagrant

I am using Chef-solo, Berkshelf and Vagrant to try to build a development environment. I have other recipes working but the 'chef-rvm' cookbook is giving me trouble for getting a ruby version installed.
To be clear, RVM is installing but when I 'vagrant ssh' into the vbox and type 'rvm list' it says there are no rubies installed. I can type 'rvm install 2.1.1' and it works so I'm not sure why Chef isn't installing it.
Vagrantfile:
config.vm.provision :chef_solo do |chef|
chef.run_list = %w[
recipe[apt::default]
recipe[rvm::user_install]
recipe[rvm::vagrant]
]
end
recipes/default.rb:
include_recipe 'apt'
include_recipe 'rvm::user_install'
attributes/default.rb:
node.set['rvm']['user_installs'] = [
{ 'user' => 'vagrant',
'upgrade' => 'head',
'default_ruby' => '2.1.1',
'rvm_gem_options' => '',
'rubies' => ['2.1.1', '2.0.0-p481'],
'global_gems' => [
{ 'name' => 'bundler',
'version' => '1.6.2'
},
{ 'name' => 'rake' },
{ 'name' => 'rails' },
{ 'name' => 'rubygems-bundler',
'action' => 'remove'
}
]
}
]

I thought it should be the default action, but I have the same problem as you.
My solution was to include the "install_ruby" property in the json config:
node.set['rvm']['user_installs'] = [
{ 'user' => 'vagrant',
install_rubies: true,
...
}
]

Related

Ruby script Net::SSH::HostKeyMismatch but ssh works

I can ssh into a remote host on my aws network but using net/ssh fails in a ruby script. my gem is net-ssh(4.2.0) on Ubuntu 16.04. It doesn't prompt for a passphrase even with non_interactive => false.
error:
Authentication failed for user Net::SSH::AuthenticationFailed
Why does this code fail?
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
HOST = 'myhost'
Net::SSH.start(HOST,
:auth_methods => ['publickey'],
:passphrase => 'mypassphrase',
:non_interactive => true,
:host_key => "ssh-rsa",
:keys => [ '/home/markhorrocks/.ssh/id_rsa' ]
) do |session|
output = session.exec!('ls')
puts output
end
After editing my code to this I get error
(Net::SSH::HostKeyMismatch)
HOST = 'myhost'
USER = 'markhorrocks'
Net::SSH.start(HOST, USER,
:auth_methods => ['publickey'],
:passphrase => 'mypassphrase',
:non_interactive => true,
:host_key => "ssh-rsa",
:encryption => "blowfish-cbc",
:keys => [ '/home/markhorrocks/.ssh/id_rsa' ],
:port => '1234',
:forward_agent => true,
:compression => "zlib#openssh.com"
) do |session|
output = session.exec!('ls')
puts output
end
The keys array needs to point at your private key(s). authorized_keys is the public fingerprints for keys allowed to log in to the current host. Also you seem to have put a private key type in for host_key.
Here is my solution:
#!/usr/bin/env ruby
require 'net/ssh'
HOST = 'myhost'
USER = 'markhorrocks'
Net::SSH.start(HOST, USER,
:auth_methods => ['publickey'],
:passphrase => 'mypassphrase',
:non_interactive => true,
:host_key => "ssh-rsa",
:encryption => "blowfish-cbc",
:keys => [ '/home/markhorrocks/.ssh/id_rsa' ],
:port => '1234',
:forward_agent => true,
:verify_host_key => false,
:compression => "zlib#openssh.com"
) do |session|
begin
rescue Net::SSH::HostKeyMismatch => e
puts "remembering new key: #{e.fingerprint}"
e.remember_host!
retry
end
output = session.exec!('ls')
puts output
end

Chef Solo in Vagrant: How to create RabbitMQ virtual host nad bind it to given username

I have a virtual machine created in Vagrant (a simple hashicorp/precise64). I need to provision it with RabbitMq and I would:
Create username testUsr with testPass as password with administration role
Create a virtual host testVirtualHost
Bind testVirtualHost to testUsr
This is my attempt:
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provision "chef_solo" do |chef|
chef.add_recipe "rabbitmq"
chef.json = {
'rabbitmq' => {
'default_user' => 'testUsr',
'default_pass' => 'testPass',
'virtualhosts' => ['testVirtualHost'],
'enabled_users' => [
{
'name' => 'testUsr',
'password' => 'testPass',
'rights' => [{ 'vhost' => 'testVirtualHost', 'conf' => '.*', 'write' => '.*', 'read' => '.*' }]
}
]
}
}
end
config.vm.network "forwarded_port", guest: 15672, host: 15672, id: "rabbitmq"
end
The user and password is created but virtual host isn't. Where is the mistake?
Here is an amended Vagrantfile based on your requirements:
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provision "chef_solo" do |chef|
chef.add_recipe "rabbitmq::user_management"
chef.add_recipe "rabbitmq::mgmt_console"
chef.json = {
'rabbitmq' => {
'default_user' => 'testUsr',
'default_pass' => 'testPass',
'virtualhosts' => ['testVirtualHost'],
'enabled_users' => [
{
'name' => 'testUsr',
'password' => 'testPass',
'rights' => [{ 'vhost' => 'testVirtualHost', 'conf' => '.*', 'write' => '.*', 'read' => '.*' }],
'tag' => 'administrator'
}
]
}
}
end
config.vm.network "forwarded_port", guest: 15672, host: 15672, id: "rabbitmq"
end
Below are the changes and additions I made:
Create username testUsr with testPass as password with administration role
For the testUsr to be an administrator, this user needed to be tagged with 'administrator' permissions:
'enabled_users' => [
{
'name' => 'testUsr',
'password' => 'testPass',
'rights' => [{ 'vhost' => 'testVirtualHost', 'conf' => '.*', 'write' => '.*', 'read' => '.*' }],
'tag' => 'administrator'
}
Create a virtual host testVirtualHost
The change here was not to call the rabbitmq recipe but call the rabbitmq::user_management recipe instead:
chef.add_recipe "rabbitmq::user_management"
This recipe calls the rabbitmq recipe. Part of the user_management code will create the testVirtualHost.
Bind testVirtualHost to testUsr
You already had the code in place for this. The change was as above (calling rabbitmq::user_management recipe)
I also noticed that you were port forwarding to the rabbitmq management console. For the console to work you would need to enable the rabbitmq_management plugin as per management.
I added:
chef.add_recipe "rabbitmq::mgmt_console"
as the mgmt_console recipe manages that plugin.
You will now be able to access the management console via http://localhost:15672

CakePHP 3: DebugKit is not enabled

I downloaded the DebugKit plugin using:
php composer.phar require --dev cakephp/debug_kit "~3.0"
But it still shows warning in error.log and DebugKit is not working:
Warning: DebugKit not enabled. You need to either install
pdo_sqlite, or define the "debug_kit" connection name
So how to define debug_kit connection name in app.php and how to enable debugkit??
Installing and enabling pdo_sqlite from Terminal
For PHP5.6
sudo apt-get install php5.6-sqlite3
For PHP7
sudo apt-get install php7*-sqlite3
After installation, Restart Apache Server
sudo service apache2 restart
Note: php5.6-sqlite3 = {YourPhpVersion}-{SqliteVersion}
In app file:
.../config/app.php
in option "Datasources": create new sub option like this:
'debug_kit' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => DB_HOST,
'port' => DB_PORT,
//'port' => 'non_standard_port_number',
'username' => DB_ACC,
'password' => DB_PASS,
'database' => DB_NAME,
//'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,'quoteIdentifiers' => false,
'url' => env('DATABASE_URL', null),
]
Save file app and refresh your website. Done.

Chef Attribute set a variable in an array hash

In a cookbook I have the following in my attributes/default.rb:
default.ark.packages = [
{
'name' => 'optipng',
'url' => 'http://squirrelyjim.cloudfront.net/heroes/optipng-0.7.5.tar.gz',
'version' => '0.7.5'
},
{
'name' => 'imagemagick',
'url' => 'http://squirrelyjim.cloudfront.net/heroes/ImageMagick-6.9.0-4.tar.gz',
'version' => '6.9.0-4'
},
{
'name' => 'jpegoptim',
'url' => 'http://squirrelyjim.cloudfront.net/heroes/jpegoptim-1.4.1.tar.gz',
'version' => '1.4.1'
}
]
I then call those values using the ark resource as follows:
node.ark.packages.each do |pkg|
ark pkg['name'] do
url pkg['url']
version pkg['version']
action :install_with_make
notifies :run, "execute[ldconfig]", :immediately
end
end
This works great but I would like to somehow get the version to automatically get called at the end of the url, instead of typing it out twice. Is there a way to get a value in a hash updated with another value from the same hash, similar to:
http://squirrelyjim.cloudfront.net/heroes/optipng-#{version}.tar.gz
Dynamically build the URL inside the loop:
node.ark.packages.each do |pkg|
url = "http://squirrelyjim.cloudfront.net/heroes/#{pkg['name']}-#{pkg['version']}.tar.gz"
ark pkg['name'] do
url url
version pkg['version']
action :install_with_make
notifies :run, "execute[ldconfig]", :immediately
end
end

puppet recipe installing tarball

I would like to install apache maven by using puppet recipe, but I can not find anywhere an example on how to do this. Can someone help with this? Apache maven is packed as tar.gz file. I am using a stand-alone setup for puppet.
I use this snippet from example42:
define netinstall (
$url,
$extracted_dir,
$destination_dir,
$owner = "root",
$group = "root",
$work_dir = "/var/tmp",
$extract_command = "tar -zxvf",
$preextract_command = "",
$postextract_command = ""
) {
$source_filename = urlfilename($url)
if $preextract_command {
exec {
"PreExtract $source_filename":
command => $preextract_command,
before => Exec["Extract $source_filename"],
refreshonly => true,
}
}
exec {
"Retrieve $url":
cwd => "$work_dir",
command => "wget $url",
creates => "$work_dir/$source_filename",
timeout => 3600,
}
exec {
"Extract $source_filename":
command => "mkdir -p $destination_dir && cd $destination_dir && $extract_command $work_dir/$source_filename",
unless => "find $destination_dir | grep $extracted_dir",
creates => "${destination_dir}/${extracted_dir}",
require => Exec["Retrieve $url"],
}
if $postextract_command {
exec {
"PostExtract $source_filename":
command => $postextract_command,
cwd => "$destination_dir/$extracted_dir",
subscribe => Exec["Extract $source_filename"],
refreshonly => true,
timeout => 3600,
require => Exec["Retrieve $url"],
}
}
}
example usage:
#Install prerequisites
exec { "VPSMonPrerequisites":
command => "yum install -y ${vpsmonitor::params::prerequisites}",
unless => "rpm -qi ${vpsmonitor::params::prerequisites}",
timeout => 3600,
}
#Install tgz from source url
netinstall { vpsmonitor:
url => "${vpsmonitor::params::source_url}",
extracted_dir => "${vpsmonitor::params::extracted_dir}",
destination_dir => "${vpsmonitor::params::destination_dir}",
postextract_command => "chown -R user. ${vpsmonitor::params::destination_dir}/${vpsmonitor::params::extracted_dir}",
require => [ Exec["VPSMonPrerequisites"], User["user"] ],
}
There is a Puppet module that does this job for you: dsestero/download_uncompress
Example:
$phpstorm_version = '2017.2.1'
download_uncompress { 'PhpStorm':
download_base_url => 'https://download.jetbrains.com/webide',
distribution_name => "PhpStorm-${phpstorm_version}.tar.gz",
dest_folder => '/opt',
creates => "/opt/phpstorm-${phpstorm_version}",
uncompress => 'tar.gz',
}

Resources