Chef: grafana community recipe error - ruby

I'm using the following recipe from chef supermarket: https://supermarket.chef.io/cookbooks/grafana
When I try to execute the following code it crashes:
grafana_user 'lechucico' do
user(
name: 'lechucico',
email: 'lechucico#example.com',
password: 'lechu',
isAdmin: true,
organizations: [
{ name: 'Administration', role: 'Admin' },
{ name: 'Marketing', role: 'Admin' }
]
)
action :create
end
This error raises:
Chef::Exceptions::ValidationFailed
==> default: ----------------------------------
==> default: Option user must be a kind of [String]! You passed {"name"=>"lechucico", "email"=>"lechucico#example.com", "password"=>"lechu", "isAdmin"=>true, "organizations"=>[{"name"=>"Administration", "role"=>"Admin"}, {"name"=>"Marketing", "role"=>"Admin"}]}.
==> default:
==> default: Cookbook Trace:
==> default: ---------------
==> default: /var/chef/cache/cookbooks/living-grafana/recipes/default.rb:50:in `block in from_file'
==> default: /var/chef/cache/cookbooks/living-grafana/recipes/default.rb:49:in `from_file'
==> default:
==> default: Relevant File Content:
==> default: ----------------------
==> default: /var/chef/cache/cookbooks/living-grafana/recipes/default.rb:
==> default:
==> default: 43: # )
==> default: 44: # action :update
==> default: 45: #end
==> default: 46:
==> default: 47: grafana_organization 'Marketing'
==> default: 48:
==> default: 49: grafana_user 'lechucico' do
==> default: 50>> user(
==> default: 51: 'name' => 'lechucico',
==> default: 52: 'email' => 'lechucico#example.com',
==> default: 53: 'password' => 'lechu',
==> default: 54: 'isAdmin' => true,
==> default: 55: 'organizations' => [
==> default: 56: { 'name' => 'Administration', 'role' => 'Admin' },
==> default: 57: { 'name' => 'Marketing', 'role' => 'Admin' }
==> default: 58: ]
==> default: 59: )
==> default:
==> default: Platform:
==> default: ---------
==> default: x86_64-linux
Why this isn't working?
Some links with information:
https://github.com/JonathanTron/chef-grafana
https://github.com/JonathanTron/chef-grafana/pull/136

That's due to the fact that despite the pull request has been merged into master, there was no release of the code within master to supermarket.
According to the comments on this issue the ownership of the cookbook is likely to move to the sous-chef group.
If you rely on this latest code, you should download it from git, change its version and push to your chef-server.
You may wish to join Slack #sous-chefs channel on http://community-slack.chef.io/ for more information on the takeover process.

Related

Guest OS Type invalid for Windows 10 in Packer

We are trying vagrant for creating windows 10 virtual box image for one of our projects internally. As part of it, I got windows 10 64 bit disc image and did some research on creating custom image using our own OS disc. Hashicorp has Packer application along with vagrant which helps in creating virtual box using custom images.
Using packer, I have created my json file, template file, validated it and ran build command to create a virtual box, but the build fails at guest OS type and couldnt figure out what is the correct guest OS type name for windows 10. I am attaching my json file, template file, build logs for your reference. Any idea can be greatly appreciated!!
Windows-10.json
{
"builders": [
{
"type": "virtualbox-iso",
"iso_url": "{{user `iso_url`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"headless": false,
"boot_wait": "2m",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "2h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"guest_os_type": "windows-10",
"disk_size": 61440,
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"2048"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
]
]
}
],
"post-processors":[
{
"type": "vagrant",
"keep_input_artifact": false,
"output": "windows_10_{{.Provider}}.box",
"vagrantfile_template": "windows10.template"
}
],
"variables": {
"iso_url":
"C:/ABC/Vagrant/Windows_10/SW_DVD5_Win_Pro_10_1511.1_64BIT_English_MLF_X20-93914.iso",
"iso_checksum_type": "md5",
"iso_checksum": "bd09dc56c51a6ce137b8c0eb7c4369ea",
"autounattend": "./answer_files/10/Autounattend.xml"
}
}
My windows 10 template looks like below
Windows10.template
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.2"
Vagrant.configure("2") do |config|
config.vm.define "vagrant-windows-10"
config.vm.box = "windows_10"
config.vm.communicator = "winrm"
# Admin user name and password
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.guest = :windows
config.windows.halt_timeout = 15
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", auto_correct: true
config.vm.provider :virtualbox do |v, override|
#v.gui = true
v.customize ["modifyvm", :id, "--memory", 2048]
v.customize ["modifyvm", :id, "--cpus", 2]
v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
end
config.vm.provider :vmware_fusion do |v, override|
#v.gui = true
v.vmx["memsize"] = "2048"
v.vmx["numvcpus"] = "2"
v.vmx["ethernet0.virtualDev"] = "vmxnet3"
v.vmx["RemoteDisplay.vnc.enabled"] = "false"
v.vmx["RemoteDisplay.vnc.port"] = "5900"
v.vmx["scsi0.virtualDev"] = "lsisas1068"
end
config.vm.provider :vmware_workstation do |v, override|
#v.gui = true
v.vmx["memsize"] = "2048"
v.vmx["numvcpus"] = "2"
v.vmx["ethernet0.virtualDev"] = "vmxnet3"
v.vmx["RemoteDisplay.vnc.enabled"] = "false"
v.vmx["RemoteDisplay.vnc.port"] = "5900"
v.vmx["scsi0.virtualDev"] = "lsisas1068"
end
end
Windows10.json has been successfully validated and when am running packer build, below is the error i get
packer build windows10.json
virtualbox-iso output will be in this color.
==> virtualbox-iso: Downloading or copying Guest additions
virtualbox-iso: Downloading or copying:
file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
virtualbox-iso: Downloading or copying: file:///C:/ABC/Vagrant/Windows_10/SW_DVD5_Win_Pro_10_1511.1_64BIT_English_MLF_X20-93914.iso
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Error creating VM: VBoxManage error: VBoxManage.exe: error: Guest OS type 'windows-10' is invalid
==> virtualbox-iso: VBoxManage.exe: error: Details: code
VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee IUnknown
==> virtualbox-iso: VBoxManage.exe: error: Context: "CreateMachine(bstrSettingsFile.raw(), bstrName.raw(), ComSafeArrayAsInParam(groups), bstrOsTypeId.raw(), createFlags.raw(), machine.asOutParam())" at line 273 of file VBoxManageMisc.cpp
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Error creating VM: VBoxManage error:
VBoxManage.exe: error: Guest OS type 'windows-10' is invalid
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee IUnknown
VBoxManage.exe: error: Context: "CreateMachine(bstrSettingsFile.raw(), bstrName.raw(), ComSafeArrayAsInParam(groups), bstrOsTypeId.raw(), createFlags.raw(), machine.asOutParam())" at line 273 of file VBoxManageMisc.cpp
==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Error creating VM: VBoxManage error: VBoxManage.exe: error: Guest OS type 'windows-10' is invalid
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee IUnknown
VBoxManage.exe: error: Context: "CreateMachine(bstrSettingsFile.raw(), bstrName.raw(), ComSafeArrayAsInParam(groups), bstrOsTypeId.raw(), createFlags.raw(), machine.asOutParam())" at line 273 of file VBoxManageMisc.cpp
==> Builds finished but no artifacts were created.
See the documentation Packer docs guest_os_type. Just run VBoxManage list ostypes and you will find that you should use Windows10_64.

vagrant puppet, composer unable to install laravel

I just recently knew about puppet and I'm trying to install laravel while vagrant is provisioning so that everything is already set (can be able to run laravel) when I logged in/ssh to vagrant. But I got stuck, it returned successfully executed but after I do vagrant ssh, laravel command is not available.
php5, php5-cli, etc. composer and other dependencies is already installed before this part of code.
class laravel {
Exec {
path => "/bin:/sbin:/usr/bin:/usr/sbin",
}
exec { "install-laravel" :
command => "/usr/local/bin/composer global require 'laravel/installer'",
require => [Package["php5-cli", "php5-dev"], Exec["install-composer", "set-composer-as-global"]],
cwd => "/home/vagrant/",
environment => ["COMPOSER_HOME=/home/vagrant"],
user => root,
group => root,
}
exec { "add-laravel-command" :
command => "mkdir /usr/local/bin/laravel",
environment => ["LARAVEL_HOME=/home/vagrant"],
onlyif => "test -d /usr/local/bin/composer",
require => Exec["install-laravel"],
user => root,
}
exec { "set-laravel-as-globall" :
command => "mv /home/vagrant/.composer/vendor/bin /usr/local/bin/laravel",
onlyif => "test -d /.composer/vendor/bin",
require => Exec["add-laravel-command"],
user => root,
}
}
Output
==> default: Notice: /Stage[main]/Laravel/Exec[install-laravel]/returns: executed successfully
==> default: Debug: /Stage[main]/Laravel/Exec[install-laravel]: The container Class[Laravel] will propagate my refresh event
==> default: Debug: Exec[add-laravel-command](provider=posix): Executing check 'test -d /usr/local/bin/composer'
==> default: Debug: Executing 'test -d /usr/local/bin/composer'
==> default: Debug: Exec[set-laravel-as-globall](provider=posix): Executing check 'test -d /.composer/vendor/bin'
==> default: Debug: Executing 'test -d /.composer/vendor/bin'
==> default: Debug: Class[Laravel]: The container Stage[main] will propagate my refresh event
Any help would be much appreciated. Thanks
create a file under puppet/modules/laravel/files and name it composer.json with the following content
{
"require": {
"laravel/installer": "^1.3"
}
}
Laravel init.pp file
class laravel {
Exec {
path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin",
user => root,
group => root,
}
file { "/usr/local/bin/laravel-devtools" :
ensure => directory,
owner => root,
group => root,
}
file { "/usr/local/bin/laravel-devtools/composer.json" :
source => "puppet:///modules/laravel/composer.json",
require => File["/usr/local/bin/laravel-devtools"],
owner => root,
group => root,
}
exec { "install-laravel" :
command => "sudo composer require 'laravel/installer'",
onlyif => "test -f /usr/local/bin/composer",
require => [
Package["nginx","php5-cli", "php5-dev", "php5-mysql"],
File["/usr/local/bin/laravel-devtools", "/usr/local/bin/laravel-devtools"],
],
environment => ["COMPOSER_HOME=/home/vagrant"],
cwd => "/usr/local/bin/laravel-devtools",
user => root,
group => root,
}
exec { "set-laravel-as-global" :
command => "sudo ln -s /usr/local/bin/laravel-devtools/vendor/laravel/installer/laravel /usr/local/bin/laravel",
require => [
File["/usr/local/bin/laravel-devtools", "/usr/local/bin/laravel-devtools/composer.json"],
Exec["install-laravel"],
],
}
}
Make sure composer is installed first during provision.

Tomact7 chef cookbook ssl problems

I'm trying to set up a chef recipe for automatic deployment of my app over ssl with tomcat chef cookbook.
It works fine without ssl, but when I try to set the attributes for ssl support I'm getting error:
undefined method `truststore_password' for Custom resource tomcat_instance from cookbook tomcat.
My role:
name "myapp"
override_attributes ({
"java" => {
"jdk_version"=> "6"
},
"oracle" => {
"accept_oracle_download_terms" => true
},
"tomcat" => {
"base_version" => 7,
"java_options" => "${JAVA_OPTS} -Xmx128M -Djava.awt.headless=true",
"secure" => true,
"client_auth" => true,
"scheme" => "https",
"ssl_enabled_protocols" => "TLSv1",
"keystore_password" => "mypass",
"truststore_password" => "mypass",
"ciphers" => "SSL_RSA_WITH_RC4_128_SHA",
"keystore_file" => "/etc/tomcat7/client.jks",
"truststore_file" => "/etc/tomcat7/cert.jks"
}
})
run_list "recipe[java]", "recipe[tomcat]"
Maybe I'm missing something, because I can't find any good tutorials on how to do this I'm also using chef-solo with vagrant.
If you look at the Tomcat cookbook documentation, you will see the following regarding the truststore_password attribute:
node['tomcat']['truststore_password'] - Generated by the secure_password method from the
openssl cookbook; if you are using Chef Solo,
set this attribute on the node
Perhaps this means that you can not set the attribute in your role definition whilst using Chef Solo, and you have to manually add it to the node attributes JSON file.

Vagrant/Puppet - Provision Failing (MySQL Not Working)

I have tried different virtual boxes, I have changed tons of configurations (probably recreated, reloaded and reprovisioned 50-100 times) -- it has to do with the MySQL module from Puppet -- which is apparently working for tens of thousands of others, so something I am doing is wrong.
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
# Was necessary
#vagrant plugin install vagrant-vbguest
# Networking
config.vm.network "forwarded_port", guest: 80, host: 8000
# config.vm.network "private_network", ip: "192.168.33.10"
# Synced folders
config.vm.synced_folder ".", "/var/www"
# Update
config.vm.provision "shell", inline: "apt-get -y update"
# Provisioning
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
(puppet module install example42-puppi; true)
(puppet module install example42-apache; true)
(puppet module install example42-php; true)
(puppet module install puppetlabs-stdlib; true)
(puppet module install puppetlabs-mysql; true)
(puppet module install saz-vim; true)
(puppet module install saz-timezone; true)
(puppet module install puppetlabs-git; true)
(puppet module install tPl0ch-composer; true)
"
end
config.vm.provision "puppet" do |puppet|
puppet.facter = {
"fqdn" => "development.mydomain.com",
"aliases" => "*.development.mydomain.com",
"hostname" => "www",
"docroot" => '/var/www/html/',
}
puppet.hiera_config_path = "manifests/hiera.yaml"
puppet.working_directory = "/etc/puppet"
end
end
Puppet File: default.pp
###########################
# MySite Puppet Config #
###########################
# OS : Ubuntu 14 #
# Database : MySQL 5 #
# Web Server : Apache 2 #
# PHP version : 5.4 #
###########################
# Vim
class { 'vim': }
# Set Timezone
class { 'timezone':
timezone => 'America/Chicago',
}
# Puppi
class { 'puppi': }
# Apache setup
class { "apache":
puppi => true,
puppi_helper => "myhelper",
}
apache::vhost { $fqdn :
docroot => $docroot,
server_name => $fqdn,
serveraliases => $aliases,
priority => '',
template => 'apache/virtualhost/vhost.conf.erb',
}
apache::module { 'rewrite': }
apache::module { 'headers': }
# PHP Extensions
class {"php":}
php::module { ['xdebug', 'mysql', 'curl', 'gd', 'mcrypt']:
notify => Service['apache2']
}
# MySQL Server
class { '::mysql::server':
package_ensure => present,
root_password => '[root_password]',
override_options => { 'mysqld' => { 'default_time_zone' => 'America/Chicago' } },
}
class { 'mysql::client':}
mysql::db { '[db_name]':
user => '[user]',
password => '[password]',
host => 'localhost',
grant => ['ALL'],
charset => 'utf8',
}
exec { "database_import":
timeout => 300,
command => "/bin/gzip -dc /vagrant/manifests/provision.sql.gz | /usr/bin/mysql -u root -p[root_password]";
}
mysql::db { '[db_test]':
user => '[user_test]',
password => '[password_test]',
host => 'localhost',
grant => ['ALL'],
charset => 'utf8',
sql => "/var/www/test/db-schema.sql",
}
# Install Composer components
include composer
composer::exec { 'install':
cmd => 'install', # REQUIRED
cwd => '/var/www', # REQUIRED
dev => true, # Install dev dependencies
}
# Git
include git
# MySite Setup
file { $docroot:
ensure => 'directory',
}
$writeable_dirs = ["${docroot}cache/", "${docroot}cache/css/", "${docroot}cache/css/js/"]
file { $writeable_dirs:
ensure => "directory",
mode => '0777',
require => File[$docroot],
}
file { '/var/www/cl/':
ensure => directory
}
file { 'errors_log':
path => "/var/www/cl/errors.log",
ensure => present,
mode => 0777,
}
# Cron Jobs
cron { thirty_minutes:
command => "/usr/bin/php ${docroot}cl-load.php crons/thirty_minutes/",
user => root,
minute => '*/30'
}
cron { hourly:
command => "/usr/bin/php ${docroot}cl-load.php crons/hourly/",
user => root,
hour => '*',
minute => 0,
}
cron { four_hours:
command => "/usr/bin/php ${docroot}cl-load.php crons/four_hours/",
user => root,
hour => '*/4',
minute => 0,
}
cron { daily:
command => "/usr/bin/php ${docroot}cl-load.php crons/daily/",
user => root,
monthday => '*',
hour => '0',
minute => 0,
}
Here is the error message I am receiving (the first):
==> ==> default: Error: Could not start Service[mysqld]: Execution of '/sbin/start mysql' returned 1:
It seems that Puppet is trying to import the database before installing the MySQL server package.
Keep in mind that Puppet don't care about which resources you write first, if you need to manage something in a specific order you have to declare relationships explicitly. So in your case the following statement:
exec { "database_import":
timeout => 300,
command => "/bin/gzip -dc /vagrant/manifests/provision.sql.gz | /usr/bin/mysql -u root -p[root_password]",
require => Class['::mysql::server']
}
Could set the correct order for that resource. Possibly you'll need to declare additional relationships in a similar manner.

Can I move parts of chef.json to databags?

I'm using vagrant + chef-solo + barkshelf plugin. In my Vagrantfile I have this:
chef.json = {
"postgresql" => {
"password" => {
"postgres" => "password"
}
},
"database" => {
"create" => ["chembl_18"]
},
"build_essential" => {
"compiletime" => true
}
}
if I add some more configuration here, my Vagrantile will quickly become messy. I was trying to chenge this, so I've created databags/postgresql/json_attribs.json file with following content:
{
"postgresql": {
"password": {
"postgres": "iloverandompasswordsbutthiswilldo"
}
}
}
and modified contents in my Vagrantfile:
chef.json = {
:postgresql => ["json_attribs"],
"database" => {
"create" => ["chembl_18"]
},
...
}
But it doesn't work, I'm getting:
==> default: 58>> default['postgresql']['dir'] = "/etc/postgresql/#{node['postgresql']['version']}/main"
...
==> default: [2014-05-14T12:36:51+00:00] ERROR: Running exception handlers
==> default: [2014-05-14T12:36:51+00:00] ERROR: Exception handlers complete
==> default: [2014-05-14T12:36:51+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2014-05-14T12:36:51+00:00] FATAL: TypeError: can't convert String into Integer
So how and where should I place this settings in order to split them into several separate files?
No, you can't just move it to a data bag without changing the recipe code.
Attributes (that you are supplying through your vagrant config) are distinct from data bags, which also store JSON data. Data in data bags is just "lying around" in Chef Server until you read it explicitly in your cookbooks.
Reading from data bags can happen through the search(), data_bag() and data_bag_item() functions, see documentation.
To avoid cluttering your Vagrantfile, you should either use a role or a wrapper cookbook.

Resources