-
-
Save Hemanthdev/07011f8e16f0147a6db30152fadc429c to your computer and use it in GitHub Desktop.
knife command parallel exec in hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| SH_KNIFE="/usr/local/chef/chef-repo/knife_parallel.bash" | |
| LOG_FILE="/usr/local/chef/chef-repo/knife_base.log" | |
| func_usage() { | |
| echo "Usage: `basename $0` {bootstrap|prepare|cook}" | |
| return 0 | |
| } | |
| if [ $# -lt 1 ]; then | |
| func_usage | |
| exit 1 | |
| fi | |
| case $1 in | |
| bootstrap) | |
| COMMAND="bootstrap" | |
| ;; | |
| cook) | |
| COMMAND="cook" | |
| ;; | |
| prepare) | |
| COMMAND="prepare" | |
| ;; | |
| *) | |
| func_usage | |
| exit 2 | |
| ;; | |
| esac | |
| ROLES=("web" "db" "adm" "bat" "mng") | |
| for role in ${ROLES[@]}; do | |
| echo "### `date +'%Y/%m/%d %H:%M:%S'`[START]: ROLE is ${role}" | tee -a ${LOG_FILE} | |
| ${SH_KNIFE} ${COMMAND} ${role} | |
| ret=$? | |
| if [ ${ret} -ne 0 ]; then | |
| echo "### `date +'%Y/%m/%d %H:%M:%S'`[ERROR]: ROLE is ${role}, loopup ${LOGFILE}" | tee -a ${LOG_FILE} | |
| fi | |
| done | |
| echo "### `date +'%Y/%m/%d %H:%M:%S'`[END]" >> ${LOG_FILE} | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| func_usage() { | |
| echo "Usage: `basename $0` {bootstrap|prepare|cook} {role}" | |
| return 0 | |
| } | |
| if [ $# -lt 2 ]; then | |
| func_usage | |
| exit 1 | |
| fi | |
| case $1 in | |
| bootstrap) | |
| COMMAND="bootstrap" | |
| ;; | |
| cook) | |
| COMMAND="cook" | |
| ;; | |
| prepare) | |
| COMMAND="prepare" | |
| ;; | |
| *) | |
| func_usage | |
| exit 2 | |
| ;; | |
| esac | |
| ROLE="$2" | |
| cat /etc/hosts | grep ${ROLE} | grep -v "127.0.0.1" | grep -v ^$ | awk '{print $NF}' | | |
| parallel -k -j+0 "knife solo ${COMMAND} {} -c ~/.chef/knife.rb -r \""role[${ROLE}]\""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment