[ Vagrant ] powershell

  1. vagrant up
vagrant up

then we stuck at

DEBUG push: finalizing
INFO subprocess: Starting process: ["C:\\Windows\\System32\\WindowsPowerShell\\
v1.0\\/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionP
olicy", "Bypass", "-Command", "$PSVersionTable.PSVersion.Major"]
INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: 2

2. kill powershell in task manager

3. the vagrant continue

DEBUG push: finalizing
INFO subprocess: Starting process: ["C:\\Windows\\System32\\WindowsPowerShell\\
v1.0\\/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionP
olicy", "Bypass", "-Command", "$PSVersionTable.PSVersion.Major"]
INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: 2
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 31980
DEBUG subprocess: Exit status: 1
INFO environment: Running hook: environment_unload
INFO host: Autodetecting host type for [#<Vagrant::Environment: C:/Users/Phongs
athorn.E/Desktop/toaster>]
DEBUG host: Trying: alt
DEBUG host: Trying: arch
DEBUG host: Trying: darwin
DEBUG host: Trying: freebsd
DEBUG host: Trying: gentoo
DEBUG host: Trying: redhat
DEBUG host: Trying: slackware
DEBUG host: Trying: suse
DEBUG host: Trying: bsd
DEBUG host: Trying: linux
DEBUG host: Trying: null
DEBUG host: Trying: windows
INFO host: Detected: windows!
INFO runner: Preparing hooks for middleware sequence...
INFO runner: 2 hooks defined.
INFO runner: Running action: environment_unload #<Vagrant::Action::Builder:0x00
000000040f3580>
ERROR vagrant: Vagrant experienced an error! Details:
ERROR vagrant: #<Vagrant::Errors::PowerShellInvalidVersion: The version of power
shell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

Installed version: N/A
Minimum required version: 3>
ERROR vagrant: The version of powershell currently installed on this host is les
s than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

Installed version: N/A
Minimum required version: 3
ERROR vagrant: C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant
/util/powershell.rb:96:in `validate_install!'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/util/powershel
l.rb:50:in `execute_cmd'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/util/platform.
rb:73:in `block in windows_admin?'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/util/platform.
rb:75:in `windows_admin?'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/plugins/providers/hyperv/p
rovider.rb:19:in `usable?'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/environment.rb
:379:in `block in default_provider'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/registry.rb:49
:in `block in each'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/registry.rb:48
:in `each'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/registry.rb:48
:in `each'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/environment.rb
:365:in `default_provider'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/plugin/v2/comm
and.rb:177:in `block in with_target_vms'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/plugin/v2/comm
and.rb:213:in `block in with_target_vms'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/plugin/v2/comm
and.rb:212:in `map'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/plugin/v2/comm
and.rb:212:in `with_target_vms'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/plugins/commands/provision
/command.rb:29:in `execute'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/cli.rb:42:in `
execute'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/lib/vagrant/environment.rb
:308:in `cli'
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-2.0.1/bin/vagrant:138:in `<main>
'
INFO interface: error: The version of powershell currently installed on this ho
st is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

Installed version: N/A
Minimum required version: 3
The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

Installed version: N/A
Minimum required version: 3
INFO interface: Machine: error-exit ["Vagrant::Errors::PowerShellInvalidVersion
", "The version of powershell currently installed on this host is less than\nthe
required minimum version. Please upgrade the installed version of\npowershell t
o the minimum required version and run the command again.\n\n Installed version
: N/A\n Minimum required version: 3"]

Example on windows 7, upgrade windows powershell to version 3 https://www.microsoft.com/en-us/download/details.aspx?id=34595 with vagrant_2.0.1_x86_64, and upgrade virtualbox to v 5.2.2 r119230

Advertisements

[ Vagrant ] command

1) Run Vagrant

$ vagrant up

verbose

$ vagrant up --debug

log to file

$ vagrant up &> vagrant.log

2) Reload Machine

vagrant reload --provision

3) SSH to vagrant VM

In Gitbash, Cygwin, or MinGW,

$ vagrant ssh

login as user : vagrant
cd to share folder

$ cd /vagrant

4) Hybernate/Shutdown/Destroy VM

>> Hybernrate

$ vagrant suspend

After we want to use, type `vagrant up`

The downside is that the virtual machine still eats up your disk space, and requires even more disk space to store all the state of the virtual machine RAM on disk.

>> Shutdown

vagrant halt

>> Destroy VM : if run `vagrant up`, vagrant need to d/l again

$ vagrant destroy

5) Vagrant Share : Create URL point to VM

Need https://atlas.hashicorp.com/ account

$ vagrant login
Username or Email: dsin
Password (will be hidden):
You're now logged in!
$ vagrant share
...
==&gt; default: Your Vagrant Share is running!
==&gt; default: URL: http://frosty-weasel-0857.vagrantshare.com

We can access on the URL

6) Vagrant on VMware, AWS

vagrant up --provider=vmware_fusion
vagrant up --provider=aws

7) More at 

https://docs.vagrantup.com/v2/

[ puppet ] file

touch the file

node "pong-VirtualBox" {
file { "/root/helloworld.txt":
ensure => file,
owner => "root",
group => "root",
mode => 0644
}
}

write file content

file {'/home/vagrant/restartMemcached.sh':
ensure => present,
content => "sudo /etc/init.d/memcached restart",
owner => "vagrant",
mode => 0744
}

write the file using templates <% %>
https://docs.puppetlabs.com/puppet/latest/reference/lang_template_erb.html

node "pong-VirtualBox" {
file { "/root/config.js":
ensure => file,
owner => "root",
group => "root",
mode => 0644,
content => template("whatever/whatever.js.erb"),
}
}

Another writing file

file_line { 'bashrc':
path => '/home/vagrant/.bashrc',
ensure => 'present',
line => 'export RAILS_ENV=development'
}

[ puppet ] package / gem install bundler / npm install bower / exec

1.bundler install

gem install bundler

equals to

package { 'bundler':
ensure => 'installed',
provider => 'gem'
}

bundle

bundle

equals to

exec { 'bundle':
user => 'vagrant',
cwd => '/vagrant',
require => Package['bundler'];
}

Bundle install

$packages = [ 'git-core']

package { $packages:
ensure => 'installed',
before => Package['bundler'],
require => [Exec['apt-get update'], Class['::mysql::server']]
}

2.npm install

npm install bower

equals to

package {'bower':
provider => 'npm',
require => Class['::nodejs']
}

[ puppet ] nodejs

Prerequisite

apt-get install puppet

Installation

sudo puppet module install puppet-nodejs --version 2.3.0

site.pp

class { '::nodejs':
manage_package_repo => false,
nodejs_dev_package_ensure => 'present',
npm_package_ensure => 'present'
}

ref : https://forge.puppet.com/puppet/nodejs

[ puppet ] MySQL

Prerequisite

apt-get install puppet

Installation

sudo puppet module install puppetlabs-mysql --version 3.10.0

site.pp

$override_options = {
'mysqld' => {
'bind-address' => '0.0.0.0'
}
}

class { '::mysql::server':
root_password => 'whatever_root_password',
# remove_default_accounts => true,
override_options => $override_options
}

ref : https://github.com/puppetlabs/puppetlabs-mysql

[ FactoryGirl ] trait

Traits : group attributes together and then apply them to any factory

Callback Example

  • after(:build) – called after a factory is built (via FactoryBot.build, FactoryBot.create)
  • before(:create) – called before a factory is saved (via FactoryBot.create)
  • after(:create) – called after a factory is saved (via FactoryBot.create)
  • after(:stub) – called after a factory is stubbed (via FactoryBot.build_stubbed)

spec/factories/users.rb

FactoryGirl.define do
  ...
  trait :with_items do
    ignore do
      number_of_items 3
    end
   after(:create) do |user, evaluator|
     (0..evaluator.number_of_items-1).each do |number|
       create(:user_item, text: "item_#{number + 1}", user_id: user.id, position: number)
     end
   end
end

Usage

let(:user_1) { 

create(:user, :with_items, number_of_items: 7) 

}

ref : https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#traits