sh 用于运行Ansible Playbooks的Quick Bash脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 用于运行Ansible Playbooks的Quick Bash脚本相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env bash
########################## REQUIREMENTS
# sudo apt-get install ansible unzip
########################## VARIBLES
PLAYBOOK_GZ="playbook.zip"
PLAYBOOK_FILE="update.yml"
INVENTORY_FILE="all"
EXTRA_ARGS="--list-tasks --list-hosts"
SOURCE_DIR=$(pwd)
DESTINATION_DIR=/tmp/update
LOGFILE=$SOURCE_DIR/update.log
########################## CODE
echo "Starting log" >> $LOGFILE
echo -n "Adding key... " >> $LOGFILE
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
SORTIDA=$?
echo OK >> $LOGFILE
echo -n "Cleaning folders... " >> $LOGFILE
rm -rf $DESTINATION_DIR 2> /dev/null
mkdir $DESTINATION_DIR
cp $SOURCE_DIR/$PLAYBOOK_GZ $DESTINATION_DIR
SORTIDA=$?
echo OK >> $LOGFILE
echo -n "Uncompressing update... " >> $LOGFILE
cd $DESTINATION_DIR
unzip $PLAYBOOK_GZ
rm $PLAYBOOK_GZ
SORTIDA=$?
echo OK >> $LOGFILE
echo "Updating... " >> $LOGFILE
cd $DESTINATION_DIR/playbook
ansible-playbook $PLAYBOOK_FILE -i hosts/$INVENTORY_FILE $EXTRA_ARGS >> $LOGFILE
SORTIDA=$?
echo OK >> $LOGFILE
if [ "$SORTIDA" -eq 0 ];
then
echo "Updated!"
else
echo "Update failed!"
fi
echo "Ending log" >> $LOGFILE
exit $SORTIDA
以上是关于sh 用于运行Ansible Playbooks的Quick Bash脚本的主要内容,如果未能解决你的问题,请参考以下文章
Ansible Playbooks学习
Ansible Playbooks 介绍 和 使用 二
ansible提权操作-普通用户运行playbooks进行提权
ansible学习笔记7-playbooks之执行一个playbook
自动化运维工具Ansible实战Playbooks剧本使用
[自动化] Ansible之使用Playbooks详解