Guest User

bootstrap-chef.sh

a guest
Jul 15th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. mkdir /home/vagrant/certs
  4.  
  5. CHEF_USER="ravish"
  6. CHEF_USER_FNAME="Ravish"
  7. CHEF_USER_LNAME="Tiwari"
  8. CHEF_USER_EMAIL="ravishktiwari@hotmail.com"
  9. CHEF_PASSWD="!@#xyz45"
  10. CHEF_KEY_FILE="/home/vagrant/certs/${CHEF_USER}-key.pem"
  11. ORG_SHORT="morg"
  12. ORG_NAME="my organization"
  13. ORG_USER=$CHEF_USER
  14. ORG_KEY="/home/vagrant/certs/${ORG_SHORT}-validator-key.pem"
  15.  
  16. function install() {
  17.     apt-get update -y -qq > /dev/null
  18.     apt-get upgrade -y -qq > /dev/null
  19.     apt-get -y -q install linux-headers-$(uname -r) build-essential > /dev/null
  20.  
  21.     echo -e "\033[32m Downloading Chef.  \033[0m"
  22.     echo -e "\033[32m ============================  \033[0m"
  23.     wget -P /tmp https://packages.chef.io/files/stable/chef-server/12.17.33/ubuntu/16.04/chef-server-core_12.17.33-1_amd64.deb > /dev/null
  24.     dpkg -i /tmp/chef-server-core_12.17.33-1_amd64.deb
  25.  
  26.     chown -R vagrant:vagrant /home/vagrant
  27.  
  28.     chef-server-ctl reconfigure
  29.     printf "\033c"
  30. }
  31.  
  32. function create_user() {
  33.     echo -e "\033[32m Creating Chef admin user.  \033[0m"
  34.     echo -e "\033[32m ============================  \033[0m"
  35.     sudo chef-server-ctl user-create \
  36.     $CHEF_USER \
  37.     $CHEF_USER_FNAME \
  38.     $CHEF_USER_LNAME \
  39.     $CHEF_USER_EMAIL \
  40.     $CHEF_PASSWD \
  41.     --filename "${CHEF_KEY_FILE}.pem"
  42.     chef-server-ctl user-create testlabdev Test Lab testlab@testlab.com password --filename /home/vagrant/certs/testlabdev.pem
  43. }
  44.  
  45. function create_org() {
  46.     echo -e "\033[32m Creating Chef Organization.  \033[0m"
  47.     echo -e "\033[32m ============================  \033[0m"
  48.     sudo chef-server-ctl org-create $ORG_SHORT $ORG_NAME \
  49.     --association_user $CHEF_USER --filename $ORG_KEY
  50.     chef-server-ctl org-create testcheflab "Test Chef Lab" --association_user testlabdev --filename /home/vagrant/certs/testcheflab.pem
  51. }
  52.  
  53.  
  54. # chef-server-ctl install chef-manage
  55. # chef-server-ctl reconfigure
  56. # chef-manage-ctl reconfigure --accept-license
  57.  
  58. function install_manage() {
  59.     echo -e "\033[32m Chef install additional tools.  \033[0m"
  60.     echo -e "\033[32m ============================  \033[0m"
  61.     sudo chef-server-ctl  install chef-manage --accept-license
  62.     sudo chef-server-ctl reconfigure
  63.     sudo chef-manage-ctl reconfigure
  64. }
  65.  
  66. install
  67. echo "\n\n"
  68. create_user
  69. echo "\n\n"
  70. create_org
  71. echo "\n\n"
  72. install_manage
  73. # configure hosts file for our internal network defined by Vagrantfile
  74. cat >> /etc/hosts <<EOL
  75. # vagrant environment nodes
  76. 10.0.15.10  chef.server
  77. 10.0.15.15  lb
  78. 10.0.15.22  webserver1
  79. 10.0.15.23  webserver2
  80. EOL
  81.  
  82. printf "\033c"
  83. echo -e "\033[32m Chef Console is ready: \n\t\t http://chef_server with \n\t\tlogin: $CHEF_USER \n\t\tpassword: $CHEF_PASSWD"
Add Comment
Please, Sign In to add comment