|
|
@ -1,59 +1,58 @@ |
|
|
|
#!/bin/bash |
|
|
|
SERVER=$1 |
|
|
|
LXC_HOST=$2 |
|
|
|
PLAYBOOK=$3 |
|
|
|
|
|
|
|
while [[ "$#" -gt 0 ]]; do |
|
|
|
case $1 in |
|
|
|
-f|--force) force=1; shift ;; |
|
|
|
esac |
|
|
|
shift |
|
|
|
done |
|
|
|
source $1 |
|
|
|
|
|
|
|
usage() { |
|
|
|
echo "Usage: run-lxc-playbook.sh server lxc_host playbook" |
|
|
|
echo "server - main proxmox server IP address and lxc_host that the name of lxc container" |
|
|
|
echo "lxc_host - name of lxc container" |
|
|
|
echo "playbook - playbook file" |
|
|
|
echo "Usage: run-lxc-playbook.sh path/to/env" |
|
|
|
} |
|
|
|
|
|
|
|
if [[ -z "$SERVER" ]]; then |
|
|
|
echo "You must defined SERVER as first argument" |
|
|
|
echo "You must defined SERVER" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$LXC_HOST" ]]; then |
|
|
|
echo "You must defined LXC_HOST as second argument" |
|
|
|
echo "You must defined LXC_HOST" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$PLAYBOOK" ]]; then |
|
|
|
echo "You must defined PLAYBOOK as third argument" |
|
|
|
echo "You must defined PLAYBOOK" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
PLAYBOOK_FILEPATH="playbooks/$PLAYBOOK.yml" |
|
|
|
if [[ ! -f "$PLAYBOOK_FILEPATH" ]]; then |
|
|
|
echo "Playbook file is not exists: $PLAYBOOK_FILEPATH" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$SITE_NAME" ]]; then |
|
|
|
echo "You must defined SITE_NAME" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ ! -f "$PLAYBOOK" ]]; then |
|
|
|
echo "Playbook file is not exists: $PLAYBOOK" |
|
|
|
if [[ -z "$DOMAIN_NAME" ]]; then |
|
|
|
echo "You must defined DOMAIN_NAME" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
COMMAND=$(cat <<EOF |
|
|
|
ansible-playbook -e "lxc_host=$LXC_HOST" -e="domain_name=$LXC_HOST" -e runner=lxc --ssh-common-args="-o ProxyCommand='ssh -W %h:%p -q root@$SERVER'" $PLAYBOOK |
|
|
|
EOF |
|
|
|
) |
|
|
|
|
|
|
|
if [[ -z "$force" ]]; then |
|
|
|
printf 'Launch ansible playbook:\n%s\n' "$COMMAND" |
|
|
|
read -p "Are you sure? " -n 1 -r |
|
|
|
echo # (optional) move to a new line |
|
|
|
if [[ $REPLY =~ ^[Yyн]$ ]] |
|
|
|
then |
|
|
|
/bin/bash -c "$COMMAND" |
|
|
|
fi |
|
|
|
else |
|
|
|
/bin/bash -c "$COMMAND" |
|
|
|
if [[ -z "$DATABASE_NAME" ]]; then |
|
|
|
echo "You must defined DATABASE_NAME" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
ansible-playbook \ |
|
|
|
-e "lxc_host=$LXC_HOST" \ |
|
|
|
-e "site_name=$SITE_NAME" \ |
|
|
|
-e "domain_name=$DOMAIN_NAME" \ |
|
|
|
-e "database_name=$DATABASE_NAME" \ |
|
|
|
-e "runner=lxc" \ |
|
|
|
--ssh-common-args="-o ProxyCommand='ssh -W %h:%p -q root@$SERVER'" \ |
|
|
|
$PLAYBOOK_FILEPATH |