#!/bin/bash # Parameters : # $1 is the IP address of the bootstrap node # $2 is the Chef environment name, default "Test-Laptop" if [[ $# -ne 2 ]] { echo "Usage: $[basename $0] IP-Address Chef-Environment" >> /dev/stderr exit } # Assume we are running in the chef-bcpc directory global HOSTNAME := $[hostname -f] knife client list | grep $HOSTNAME > /dev/null global RES := $Status if [[ "${RES}" -ne 0 ]] { sudo bash -c 'EDITOR=true knife client create $(hostname -f) > /etc/chef/client.pem' knife actor map knife group add actor admins $[hostname -f] } else { echo "$HOSTNAME already registered in Chef" } # Are we running under Vagrant? If so, jump through some extra hoops. if [[ -d /home/vagrant ]] { knife bootstrap -E $2 $1 -i /chef-bcpc-host/vbox/insecure_private_key -x vagrant --sudo } else { knife bootstrap -E $2 $1 -x ubuntu --sudo } knife node run_list add $[hostname -f] 'role[BCPC-Bootstrap]' sudo chef-client (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_ne left:{($ VSub_Pound "$#")} right:{(2)}) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("Usage: ") (CommandSubPart command_list: (CommandList children:[(C {(basename)} {($ VSub_Number "$0")})]) left_token: spids: [34 38] ) (" IP-Address Chef-Environment") ) } ] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(/dev/stderr)} spids:[42])] ) (C {(exit)}) ] spids: [-1 27] ) ] spids: [-1 49] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOSTNAME) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(hostname)} {(-f)})]) left_token: spids: [57 61] ) } spids: [56] ) ] spids: [56] ) (Pipeline children: [ (C {(knife)} {(client)} {(list)}) (SimpleCommand words: [{(grep)} {($ VSub_Name "$HOSTNAME")}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[75])] ) ] negated: False ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:RES) op:Equal rhs:{($ VSub_QMark "$?")} spids:[79])] spids: [79] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_ne left:{(DQ (${ VSub_Name RES))} right:{(0)}) ) terminator: ) ] action: [ (C {(sudo)} {(bash)} {(-c)} {(SQ <"EDITOR=true knife client create $(hostname -f) > /etc/chef/client.pem">)} ) (C {(knife)} {(actor)} {(map)}) (C {(knife)} {(group)} {(add)} {(actor)} {(admins)} { (CommandSubPart command_list: (CommandList children:[(C {(hostname)} {(-f)})]) left_token: spids: [130 134] ) } ) ] spids: [-1 99] ) ] else_action: [(C {(echo)} {(DQ ($ VSub_Name "$HOSTNAME") (" already registered in Chef"))})] spids: [136 146] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_d child:{(/home/vagrant)})) terminator: ) ] action: [ (C {(knife)} {(bootstrap)} {(-E)} {($ VSub_Number "$2")} {($ VSub_Number "$1")} {(-i)} {(/chef-bcpc-host/vbox/insecure_private_key)} {(-x)} {(vagrant)} {(--sudo)} ) ] spids: [-1 163] ) ] else_action: [ (C {(knife)} {(bootstrap)} {(-E)} {($ VSub_Number "$2")} {($ VSub_Number "$1")} {(-x)} {(ubuntu)} {(--sudo)} ) ] spids: [186 205] ) (C {(knife)} {(node)} {(run_list)} {(add)} { (CommandSubPart command_list: (CommandList children:[(C {(hostname)} {(-f)})]) left_token: spids: [216 220] ) } {(SQ <"role[BCPC-Bootstrap]">)} ) (C {(sudo)} {(chef-client)}) ] )