AWSでchefをインストールから実行_gitへ登録 - HarukiMuramoto/ohayou GitHub Wiki

AWSインスタンス作成後

sudo cp /usr/share/zoneinfo/Japan /etc/localtime

sudo yum update -y

chefのインストール

curl -L http://www.opscode.com/chef/install.sh | sudo bash

knife soloインストール

sudo /opt/chef/embedded/bin/gem install knife-solo --no-ri --no-rdoc

AWSの秘密鍵をおいておく

mv /home/ec2-user/<秘密鍵> ~/.ssh/

リモートへchefをインストール

knife solo prepare ec2-user@localhost -i ~/.ssh/<秘密鍵>

chefレポジトリ登録

knife solo init chef-repo

github用の秘密鍵生成

ssh-keygen -t rsa -C "github登録時のメールアドレス"

ssh-agent起動

ssh-agent -s ssh-add ~/.ssh/id_rsa

公開鍵をgithubへ登録

cat ~/.ssh/id_rsa.pub

githubへ接続確認

ssh -T [email protected]

gitインストール

sudo yum install git

git情報登録

1.git config --global user.name "<名前>" 2.git config --global user.email "<登録メールアドレス>" 3.git config --global github.user "<登録アカウント>"

token登録するため、取得しておく

curl -u '<登録アカウント>' -d '{"scopes":["repo"],"note":"Help example"}' https://api.github.com/authorizations git config --global github.token ""

gitへ登録

cd chef-repo/ git init git add . git commit -m "first commit" git remote add origin https://github.com/<アカウント>/<レポジトリ>.git git push -u origin master

cookbook作成

knife cookbook create ohayou -o site-cookbooks

recipe作成

vi site-cookbooks/ohayou/recipes/default.rb

実行レシピ登録

vi chef-repo/nodes/localhost.json

実行

sudo knife solo cook ec2-user@localhost -i ~/.ssh/<秘密鍵>

⚠️ **GitHub.com Fallback** ⚠️