Created
May 21, 2014 13:50
-
-
Save kaz-tk/6d9a20cb13fba5d97574 to your computer and use it in GitHub Desktop.
Ansible Execute Script for Primer
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 -x | |
# ----- user variable definition ----- | |
inventory="inventories/development" | |
playbook="./playbook.yml" | |
exc_direct=1 | |
flg_step=1 | |
# ----- variable definition ----- | |
_loop=0 | |
dir_base=`pwd` | |
LOGFILE=`date "+%Y%m%d_%H%M%S"` | |
inventories=() | |
inventories_index=0 | |
operations=( | |
select_inventories | |
) | |
# ----- function _definition ----- | |
function _inithelper(){ | |
echo >> hosts << __EOF__ | |
[webservers] | |
www1.example.com ansible_ssh_host=127.0.0.1 | |
__EOF__ | |
mkdir -p ./{inventories,playbooks} 2>&1 | |
} | |
function _init(){ | |
_fetch_inventories | |
} | |
function _fetch_inventories(){ | |
index=0 | |
for inventory in ./inventories/* | |
do | |
inventories=(${inventories[@]} "${inventory}") | |
done | |
} | |
function _list_menu(){ | |
printf "Base Directory: %s\n" dir | |
printf "Current Config:\n" | |
printf " Current Inventory\n" inventory | |
printf " \n" | |
} | |
function _list_inventories(){ | |
printf "==== Inventories ====\n" | |
index=0 | |
for inventory in ${inventories[@]} | |
do | |
printf "[%2d] : %s\n" $index $inventory | |
index=`expr $index + 1` | |
done | |
printf "\n" | |
} | |
function _select_index(){ | |
printf "select index\n" | |
printf "\n" | |
} | |
function _list_operation(){ | |
for op in ${operations[@]} | |
do | |
echo $op | |
done | |
} | |
function _select_operation(){ | |
_list_inventories | |
printf "selected inventories[%2d]: %s" $inventories_index ${inventories[$inventories_index]} | |
printf "\n" | |
printf "\n" | |
printf "===== select operation =====\n" | |
_list_operation | |
# ToDo: scanf | |
echo -n "Select Operation>" | |
read INPUT | |
printf "\n" | |
printf "\n" | |
} | |
function _exc_playbook(){ | |
if $flg_step -eq 0; then | |
ansible-playbook -i ${inventories[$inventories_index]} --extra-vars "LOGFILE=${LOGFILE}" $playbook | |
elif $flg_step -eq 1; then | |
ansible-playbook -i ${inventories[$inventories_index]} --extra-vars "LOGFILE=${LOGFILE}" $playbook --step | |
fi | |
} | |
function _main(){ | |
_fetch_inventories | |
while [ ${_loop} -eq 0 ] | |
do | |
# ToDo | |
printf $exc_direct | |
if $exc_direct -eq 0; then | |
_loop=1 | |
_exc_playbook | |
else | |
_select_operation | |
fi | |
done | |
} | |
_main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ファイルのチェック系をもうちょっと強化したいのと、
コマンドオプションの受け取りとかいいサンプル無いかな?