I'm trying to install mysql server on a vagrant vm with puppet ,I've added this line on the Vagrant file
config.vm.provision "puppet"
in the same Vagrantfile folder I've created the manifests folder and inside it folder it's default.pp with this content
class { '::mysql::server':
root_password => 'root',
remove_default_accounts => false,
override_options => $override_options
}
mysql::db { 'wordpress':
user => 'wordpress',
password => '12345',
host => 'localhost',
grant => ['ALL'],
}
But I get this error message when I execute vagrant provision
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: stdin: is not a tty
==> default: Warning: Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations
==> default: (at /usr/lib/ruby/vendor_ruby/puppet/settings.rb:1139:in `issue_deprecation_warning')
==> default: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class ::mysql::server at /tmp/vagrant-puppet/manifests-a11d1078b1b1f2e3bdea27312f6ba513/default.pp:5 on node vagrant-ubuntu-trusty-64.hitronhub.home
==> default: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class ::mysql::server at /tmp/vagrant-puppet/manifests-a11d1078b1b1f2e3bdea27312f6ba513/default.pp:5 on node vagrant-ubuntu-trusty-64.hitronhub.home
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
puppetlabs-mysql is a puppet module, which means it is not included with the base puppet executable. To use it, you'll need to do a few things:
Create a modules directory in your project for holding puppet modules
Use puppet module install --modulepath modules puppetlabs-mysql to install the MySQL module into the modules directory
Configure module_path for the puppet provisioner in your Vagrantfile
Related
I want to set up an environment with Vagrant. I defined 2 mysql in Vagrantfile, one for development, and one for integration tests. To differentiate these 2 instance I want to expose different ports.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.100.138", nic_type: "82545EM"
config.vm.define "mysql" do |m|
config.vm.provider "docker" do |d|
d.name = "mysql"
d.image = "mysql:8"
d.ports = ["3306:3306"]
d.env = {"MYSQL_DATABASE" => "development", "MYSQL_ROOT_PASSWORD" => "root"}
d.remains_running = true
end
end
config.vm.define "mysql-integration-test" do |mit|
config.vm.provider "docker" do |d|
d.name = "mysql-integration-test"
d.image = "mysql:8"
d.ports = ["3406:3306"]
d.env = {"MYSQL_DATABASE" => "development-it", "MYSQL_ROOT_PASSWORD" => "root"}
d.remains_running = true
end
end
end
The problem is when I started it I got an error than the port is already in use:
jmecsei#jmecsei:~/Work/vagrant$ vagrant up
Bringing machine 'mysql' up with 'docker' provider...
Bringing machine 'mysql-integration-test' up with 'docker' provider...
==> mysql: Creating and configuring docker networks...
==> mysql-integration-test: Creating and configuring docker networks...
==> mysql: Creating the container...
mysql: Name: mysql-integration-test
mysql: Image: mysql:8
mysql: Volume: /home/jmecsei/Work/vagrant:/vagrant
mysql: Port: 3406:3306
mysql:
mysql: Container created: 94c0f18c6938365f
==> mysql-integration-test: Fixed port collision for 22 => 2222. Now on port 2200.
==> mysql-integration-test: An error occurred. The error will be shown after all tasks complete.
==> mysql: Enabling network interfaces...
==> mysql: Starting container...
An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.
An error occurred while executing the action on the 'mysql-integration-test'
machine. Please handle this error then try again:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 3406 is already in use
on the host machine.
To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 3306, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.
My ruby version is "2.6.6", my mysql version is "5.7", my mysql2 version is 0.5.3, my rails version is 5.0.7.2, and my Xcode version is 12.5.
I use macOS Big Sur(version 11.4) and the text editor "Atom".
I'm planning to release my Rails application with the URL of HEROKU(example. https://[My APP Name].herokuapp.com).
I caused the error "Missing secret_key _base for 'production' environment" even though I set up the environment variable.
database.yml
# MySQL. Versions 5.0 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: <%= ENV.fetch("DATABASE_USERNAME") %>
password: <%= ENV.fetch("DATABASE_PASSWORD") %>
socket: /tmp/mysql.sock
development:
<<: *default
database: ****_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: ****_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass#localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
adapter: postgresql
encoding: unicode
pool: 5
database: ****_production
username: ****
password: <%= ENV['****_DATABASE_PASSWORD'] %>
secrets.yml
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
development:
secret_key_base: ****
test:
secret_key_base: ****
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
I added the GENERETED CODE of rails secret(I also executed bundle exec rake secret.) by the four following methods.
1. $ export SECRET_KEY_BASE=GENERATED CODE
2. $ heroku config:set SECRET_KEY_BASE=GENERATED CODE
I added the GENERATED CODE to ~/.bash_profile.
export SECRET_KEY_BASE=GENERATED CODE
And then I saved the above SECRET_KEY_BASE with esc, ":x" and Enter.And I executed this command$ source ~/.bash_profile.
I added the GENERATED CODE to ./env file
DATABASE_USERNAME = ****
DATABASE_PASSWORD = ****
SECRET_KEY_BASE = GENERATED CODE
end.
I verified that the environment variable is set in Linux by the three following methods:
$ heroku config:get SECRET_KEY_BASE
GENERATED CODE
or
$ printenv | grep SECRET_KEY_BASE
SECRET_KEY_BASE=GENERATED CODE
and
$ echo $SECRET_KEY_BASE
GENERATED CODE
end.
As a result, Heroku didn't open but there are two messages of the error:
I executed this command:$ heroku open.
But Heroku didn't open but the following message was displayed.
An unhandled lowlevel error occurred. The application logs may have details.
I executed this command:$ heroku logs and the following message was displayed.
#<RuntimeError: Missing `secret_key
_base` for 'production' environment, set this value in `config/secrets.yml`>
end.
I can't open Heroku ,even though I set up the environment variable ,according to the two above messages.
Maybe I think that I can't open Heroku because MySQL version currently in use "5.7" and MySQL version with this command $ mysql --version don't match.
I executed this command$ mysql --version.
$ mysql --version
mysql Ver 8.0.23 for osx10.16 on x86_64 (Homebrew)
end.
The following is the evidence that I use MySQL"5.7".
$ brew services start mysql#5.7
==> Successfully started `mysql#5.7` (label: homebrew.mxcl.mysql#5.7)
end.
What's the true cause why I can't open Heroku?
First, a couple of details:
MySQL has nothing to do with this error, so you can edit that out from your question.
Nothing in your local linux machine environment has nothing to do with the error, so you can remove any reference to printenv, echo and export.
My guess: config/secrets.yml is git-ignored
The most likely reason heroku does not see your SECRET_KEY_BASE env variable is that the secrets.yml file itself never goes to heroku.
If the config/secrets.yml file is never uploaded from your computer, heroku has no way to find it. Unlike DATABASE_URL, the secret key base does not have a "default" environment variable from which it is read.
How to check
If your project is in github/gitlab/other, you can check there, if you cannot find config/secrets.yml then it's not going to get to heroku either. If instead you don't have any other remote, check your .gitignore file (it contains the list of files that should not be uploaded when you push, to say it in some way); it probably includes a line saying config/secrets.yml.
Another way to check this is to change something (even a comment) in config/secrets.yml, and save. Then write git status in the same directory: if it says "no changes", then you have your config/secrets.yml ignored.
What to do
The easiest way is to go to config/environments/production.rb, and set your secret key base directly:
# somehwere inside the configure block
config.secret_key_base = ENV["SECRET_KEY_BASE"]
Once you commit and push this change, you should be all set.
I'm trying to connect to my vagrant MySQL server using MySQL workbench. It shows some error as shown in the image.
The workbench error log is pasted below.
17:34:50 [INF][ SSH tunnel]: Existing SSH tunnel not found, opening new one
17:34:50 [INF][ SSH tunnel]: Opening SSH tunnel to 127.0.0.1:2222
17:34:50 [ERR][ sshtunnel.py]: Traceback (most recent call last):
File "/usr/share/mysql-workbench/sshtunnel.py", line 231, in _connect_ssh
look_for_keys=has_key, allow_agent=has_key)
File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 337, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 528, in _auth
raise saved_exception
AuthenticationException: Authentication failed.
17:34:50 [ERR][ SSH tunnel]: Authentication error opening SSH tunnel: Authentication error. Please check that your username and password are correct and try again.
vagrant up command output is pasted below
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 6216 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The command vagrant ssh works fine in terminal. What am I doing wrong here?
If you run vagrant ssh-config it will show which key it is using. It does not normally use the .vagrant.d/insecure_private_key but a key in the project directory like .vagrant/machines/default/virtualbox/private_key.
If you specify that key in the MySQL connection panel you should be able to logon without having to add another key to the vm.
Regarding error you mention in comments:
When using ssh you don't specify port like this
ssh 127.0.0.1:2222
You must use option -p
ssh 127.0.0.1 -p 2222
After some googling, I got it working by adding my ssh public key to vagrant authorized_keys file. Steps Below.
generate ssh keys for your machine
copy your public key from /home/{username}/.ssh/id_rsa.pub file
open vagrant ssh in termial
use some editor to edit /home/vagrant/.ssh/authorized_keys(eg: nano /home/vagrant/.ssh/authorized_keys)
paste your public key to the end of that file and save
done!
I'm making my live easier (I hope) by learning to use puppet and vagrant.
I already know how to work with Vagrant but want to make a configuration that out of the box has everything set-up to start. So I thought to use Puppet.
I used the tutorial at http://jamesmcfadden.co.uk/using-vagrant-and-puppet-to-build-a-php-nginx-and-mysql-environment/ but can't seem to figure out how to start MySQL.
Running Ubuntu 14.04LTS my init.pp for MySQL is
class mysql {
# Install mysql
package { ['mysql-server']:
ensure => present,
require => Exec['apt-get update'],
}
# Run mysql
service { 'mysql':
ensure => running,
require => Package['mysql-server'],
}
# Use a custom mysql configuration file
file { '/etc/mysql/my.cnf':
source => 'puppet:///modules/mysql/my.cnf',
require => Package['mysql-server'],
notify => Service['mysql'],
}
# We set the root password here
exec { 'set-mysql-password':
unless => 'mysqladmin -uroot -proot status',
command => "mysqladmin -uroot password a9120ed2b58af37862a83f5b9f850819ed08b2a9",
path => ['/bin', '/usr/bin'],
require => Service['mysql'];
}
}
But this gives me an error that mysql is not found.
err: /Stage[main]/Mysql/Service[mysql]/ensure: change from stopped to running fa
iled: Could not start Service[mysql]: Execution of '/sbin/start mysql' returned
1: at /tmp/vagrant-puppet-2/modules-0/mysql/manifests/init.pp:13
And changing it to mysqld (note the 'd') this message is gone but there are problems coming up with the dependencies that can't be found to check if mysql is running (after changing them to 'Service['mysqld']':
err: /Stage[main]/Mysql/Service[mysqld]: Could not evaluate: Could not find init
script or upstart conf file for 'mysqld'
Were am I doing it wrong?
your script has the below lines:
require => Exec['apt-get update'],
but don't define the 'Exec'. Add following lines:
exec { 'apt-get update':
command => 'sudo apt-get update',
path => ['/bin', '/usr/bin'],
}
Should work fine afterward.
Do not try to write your own MySQL module. Please use officially supported puppet MySQL module. To install it call:
puppet module install puppetlabs-mysql
Generally, if you want to install/manage some application by puppet, first check if on puppet forge exist dedicated module.
I am relatively new to chef and am trying to get my head around several concepts by using Vagrant and chef-solo to provision VirtualBox machines for a local development environment.
Currently, I have a webserver role which is basically the following run_list:
"role[base]",
"recipe[php]",
"recipe[php::module_mysql]",
"recipe[apache2]",
"recipe[apache2::mod_php5]",
"recipe[apache2::mod_rewrite]",
"recipe[mysql-chef_gem]",
# "recipe[database]",
# "recipe[mysql::server]",
# "recipe[database::mysql]"
And a webapp role with the following run_list
"recipe[subversion]",
"recipe[my-app]"
All cookbooks are from opscode or community cookbooks, except my-app which is as follows (default.rb):
include_recipe "mysql::server"
include_recipe "mysql::client"
include_recipe "database"
include_recipe "database::mysql"
env = data_bag_item("environments",node.chef_environment)
subversion "MyApp" do
repository env['app']['svn']['repo']
revision "HEAD"
svn_username env['app']['svn']['username']
svn_password env['app']['svn']['password']
destination env['app']['document_root']
action :sync
end
# Set up the Apache virtual host
web_app env['app']['name'] do
server_name env['app']['name']
docroot env['app']['document_root']
template "my-app-apache.conf.erb"
end
mysql_service 'default' do
allow_remote_root true
server_root_password env['mysql']['root_password']
action :create
end
mysql_database 'default' do
database_name env['app']['db']['name']
connection(
:host => 'localhost',
:username => 'root',
:password => env['mysql']['root_password']
)
action :create
end
Everything works great until chef-client tries to run the mysql_database resource, at which point I get the following output:
[2014-06-17T15:32:19+00:00] ERROR: No resource or method named `mysql_database' for `Chef::Recipe "default"'
If I add database::mysql recipe to the run_list, it apparently automatically tries to connect with the default root password from mysql::server attributes.
I understand the "right" way to do this may be to specify the attributes in an attribute file, and put database::mysql in the runlist, but since I'm using this as an exercise to learn chef, I'd like to understand a) why my approach is not working and b) if it's possible to use the mysql_database resource by including the recipe rather than adding it to a runlist.
That resource comes from the database cookbook: https://github.com/opscode-cookbooks/database. You need to add the database cookbook to your metadata.rb and reprovision to get access to the mysql_database resource.