There are several options to run recipes:
- using chef-client with -z option
- using chef-apply
- using chef-solo
Before running Chef recipes on the machine, it should be prepared:
We have a server(node) accessible by SSH. We want to provision using Chef recipes stored on our local chef repo.
We will use gem knife-zero.
Find an example of Chef repo here.
| #!/bin/sh | |
| echo "" | |
| echo "######################################################" | |
| echo "EC2(Windows2012日本語版)インスタンス起動スクリプト." | |
| echo "######################################################" | |
| ## --------------------------------------------------------------------------- | |
| ## 実行例 | |
| ## $ ./run-windows-ec2-instance.sh \ | |
| ## -i cs-blog-role \ |
| #!/bin/bash | |
| sudo apt-get update | |
| sudo apt-get install -y openjdk-6-jre ruby1.8-full libxml2-utils unzip cpanminus build-essential | |
| sudo mkdir -p /usr/local/aws | |
| wget --quiet http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip | |
| unzip -qq ec2-api-tools.zip | |
| sudo rsync -a --no-o --no-g ec2-api-tools-*/ /usr/local/aws/ec2/ |
| #!/bin/bash | |
| set -e | |
| set -u | |
| set -o pipefail | |
| # Return netmask for a given network and CIDR. | |
| cidr_to_netmask() { | |
| value=$(( 0xffffffff ^ ((1 << (32 - $1)) - 1) )) | |
| echo "$(( (value >> 24) & 0xff )).$(( (value >> 16) & 0xff )).$(( (value >> 8) & 0xff )).$(( value & 0xff ))" |
chef-server-ctl reconfigurechef-server-ctl user-create admin Chef Administrator [email protected] <password> --filename /tmp/admin.pemchef-server-ctl org-create <org-short-name> "<org-full-name>" --association_user admin --filename /tmp/validator.pem/var/opt/opscode/nginx/ca/<fqdn>.key, /var/opt/opscode/nginx/ca/<fqdn>.crt. Restart services (nginx) with: chef-server-ctl restartchef-server-ctl reconfigurechef-server-ctl user-create admin Chef Administrator [email protected] <password> --filename /tmp/admin.pemchef-server-ctl org-create <org-short-name> "<org-full-name>" --association_user admin --filename /tmp/validator.pem/var/opt/opscode/nginx/ca/<fqdn>.key, /var/opt/opscode/nginx/ca/<fqdn>.crt. Restart services (nginx) with: chef-server-ctl restart| #!/bin/bash | |
| DOMAIN=noomii.com | |
| HOSTNAME=hotfix | |
| IPV4='184.73.226.144' | |
| # Set the host name | |
| hostname $HOSTNAME | |
| echo $HOSTNAME > /etc/hostname |
| #!/bin/bash | |
| DOMAIN=noomii.com | |
| HOSTNAME=hotfix | |
| IPV4='184.73.226.144' | |
| # Set the host name | |
| hostname $HOSTNAME | |
| echo $HOSTNAME > /etc/hostname |
| #!/bin/bash | |
| # bash generate random alphanumeric string | |
| # | |
| # bash generate random 32 character alphanumeric string (upper and lowercase) and | |
| NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
| # bash generate random 32 character alphanumeric string (lowercase only) | |
| cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 |