Skip to content

Instantly share code, notes, and snippets.

@marcy-terui
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcy-terui/f6e09a470c4b4e2af049 to your computer and use it in GitHub Desktop.
Save marcy-terui/f6e09a470c4b4e2af049 to your computer and use it in GitHub Desktop.
knifeコマンドが面倒すぎるので「knife-helper」というpluginを作ったのでチュートリアル(knife-zero,knife-ec2で) ref: http://qiita.com/Marcy/items/a314d81b78bb01a9626f
---
settings:
command_base: /Users/marcy/github/knife-helper-example/vendor/bundle/ruby/2.1.0/bin/knife
commands:
- name: create
command: ec2 server create
options:
aws-access-key-id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
aws-secret-access-key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
region: ap-southeast-1
flavor: t2.micro
image: ami-68d8e93a
tags: Name=knife-helper-example
ssh-key: knife-helper-example
subnet: subnet-3dc43e58
security-group-ids: sg-713bc314
ssh-user: ec2-user
identity-file: ~/.ssh/knife-helper-example.pem
template-file: template.erb
associate-public-ip:
- name: bootstrap
command: zero bootstrap ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
options:
node-name: knife-helper-example
environment: test
hint: ec2
ssh-user: ec2-user
identity-file: ~/.ssh/knife-helper-example.pem
sudo:
- name: converge
command: zero chef_client
condition: chef_environment:test
options:
ssh-user: ec2-user
identity-file: ~/.ssh/knife-helper-example.pem
attribute: ec2.public_ipv4
sudo:
source "https://supermarket.chef.io"
cookbook "nginx"
$ bundle exec knife helper exec bootstrap
Doing old-style registration with the validation key at ...
Delete your validation key in order to use your user credentials instead
Connecting to ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com Installing Chef Client...
<snip>
ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com Chef Client finished, 0/0 resources updated in 4.994025311 seconds
$ bundle exec berks vendor cookbooks
$ bundle exec berks vendor cookbooks
$ bundle exec knife node run_list add knife-helper-example recipe[nginx]
$ bundle exec knife helper exec converge
52.74.50.188 Starting Chef Client, version 12.2.1
52.74.50.188 resolving cookbooks for run list: ["nginx"]
<snip>
52.74.50.188 Running handlers:
52.74.50.188 Running handlers complete
52.74.50.188 Chef Client finished, 22/25 resources updated in 32.196846458 seconds
$ bundle exec knife helper exec create -p
/Users/marcy/github/knife-helper-example/vendor/bundle/ruby/2.1.0/bin/knife ec2 server create --aws-access-key-id AKIAIIKXXXXXXX --aws-secret-access-key XXXXXXXXXXXXXXXXXXXXXX --region ap-southeast-1 --flavor t2.micro --image ami-68d8e93a --tags Name=knife-helper-example --ssh-key knife-helper-example --subnet subnet-3dc43e58 --security-group-ids sg-713bc314 --ssh-user ec2-user --identity-file ~/.ssh/knife-helper-example.pem --template-file template.erb --associate-public-ip
$ bundle exec knife helper exec bootstrap -p
/Users/marcy/github/knife-helper-example/vendor/bundle/ruby/2.1.0/bin/knife zero bootstrap ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com --node-name knife-helper-example --environment test --hint ec2 --ssh-user ec2-user --identity-file ~/.ssh/knife-helper-example.pem --sudo
$ bundle exec knife helper exec converge -p
/Users/marcy/github/knife-helper-example/vendor/bundle/ruby/2.1.0/bin/knife zero chef_client 'chef_environment:test' --ssh-user ec2-user --identity-file ~/.ssh/knife-helper-example.pem --attribute ec2.public_ipv4 --sudo
$ bundle exec knife helper init -l -B
settings:
command_base: bundle exec knife
$ bundle exec knife helper exec create
Instance ID: i-ad186e60
Flavor: t2.micro
Image: ami-68d8e93a
Region: ap-southeast-1
Availability Zone: ap-southeast-1b
Security Group Ids: sg-713bc314
Tags: Name: knife-helper-example
SSH Key: knife-helper-example
Waiting for EC2 to create the instance.............
Subnet ID: subnet-3dc43e58
Tenancy: default
Public DNS Name: ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
Private IP Address: 172.31.3.169
Waiting for sshd access to become available..........done
Doing old-style registration with the validation key at ...
Delete your validation key in order to use your user credentials instead
Connecting to ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
<snip>
Instance ID: i-ad186e60
Flavor: t2.micro
Image: ami-68d8e93a
Region: ap-southeast-1
Availability Zone: ap-southeast-1b
Security Group Ids: sg-713bc314
Tags: Name: knife-helper-example
SSH Key: knife-helper-example
Root Device Type: ebs
Root Volume ID: vol-e85021e6
Root Device Name: /dev/xvda
Root Device Delete on Terminate: true
Subnet ID: subnet-3dc43e58
Tenancy: default
Public DNS Name: ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
Private IP Address: 172.31.3.169
Environment: _default
$ bundle exec knife helper exec create
Instance ID: i-ad186e60
Flavor: t2.micro
Image: ami-68d8e93a
Region: ap-southeast-1
Availability Zone: ap-southeast-1b
Security Group Ids: sg-713bc314
Tags: Name: knife-helper-example
SSH Key: knife-helper-example
Waiting for EC2 to create the instance.............
Subnet ID: subnet-3dc43e58
Tenancy: default
Public DNS Name: ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
Private IP Address: 172.31.3.169
Waiting for sshd access to become available..........done
Doing old-style registration with the validation key at ...
Delete your validation key in order to use your user credentials instead
Connecting to ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
<snip>
Instance ID: i-ad186e60
Flavor: t2.micro
Image: ami-68d8e93a
Region: ap-southeast-1
Availability Zone: ap-southeast-1b
Security Group Ids: sg-713bc314
Tags: Name: knife-helper-example
SSH Key: knife-helper-example
Root Device Type: ebs
Root Volume ID: vol-e85021e6
Root Device Name: /dev/xvda
Root Device Delete on Terminate: true
Subnet ID: subnet-3dc43e58
Tenancy: default
Public DNS Name: ec2-52-74-50-188.ap-southeast-1.compute.amazonaws.com
Private IP Address: 172.31.3.169
Environment: _default
$ bundle exec knife environment create test
source "https://rubygems.org"
gem "chef"
gem "knife-helper"
gem "berkshelf"
gem "knife-ec2"
gem "knife-zero"
local_mode true
cookbook_path ["./cookbooks", "./site-cookbooks"]
chef_repo_path "./"
bash -c '
sudo yum -y update
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment