Commit 075d3a90 authored by Visay Keo's avatar Visay Keo

Merge branch 'custom_ssh_port' into 'master'

[TASK] Enable ssh remote port option

* to override the default ssh port (22), just use --remote-port option

See merge request !3
parents ea820944 7c2f8f13
......@@ -32,6 +32,7 @@ bin-dir/syncontent --remote-user=demo-014-007
- You need to make sure that you have auto login with public key to `demo-014-007@YOUR_SERVER_HOSTNAME_OR_IP`.
The default host server is `10.10.10.27`, which is my internal web server
- You can define your own server host with `--remote-host=YOUR_SERVER_HOSTNAME_OR_IP` argument
- You can define your own server ssh port with `--remote-port=YOUR_SERVER_SSH_PORT` argument
- You can only run the command from the root directory of your project
- The document root on the server will have to be at `/home/demo-014-007/public_html`
- If you have a different document root path, you can overwrite the default with `--remote-path` argument
......@@ -39,19 +40,20 @@ The default host server is `10.10.10.27`, which is my internal web server
So the full overwriting way would be:
```bash
bin-dir/syncontent --remote-user=demo-014-007 --remote-host=10.10.10.37 --remote-path=/home/user/neosbox
bin-dir/syncontent --remote-user=demo-014-007 --remote-host=10.10.10.37 --remote-port=2222 --remote-path=/home/user/neosbox
```
Or short form of the arguments:
```bash
bin-dir/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox
bin-dir/syncontent -u=demo-014-007 -h=10.10.10.37 -P=2222 -p=/home/user/neosbox
```
### Available arguments
- `-u` | `--remote-user` : Set the login user to the remote server (__Required__)
- `-h` | `--remote-host` : Set the hostname or IP address of the remote server (__Default__: `10.10.10.27`)
- `-P` | `--remote-port` : Set the ssh port of the remote server (__Default__: `22`)
- `-p` | `--remote-path` : Set path to the document root on the remote server (__Default__: `/home/<remote-user>/public_html`)
- `-t` | `--ansible-tags`: Set the specific task you want run. See available sync tasks section for details
- `--remote-php` : Set the path to php on the remote server
......@@ -80,10 +82,11 @@ vendor-dir
└── README.md
```
You can also overwrite the default value of `--remote-host`, `--remote-path`, `--remote-php`, etc, by setting it in the created master file.
You can also overwrite the default value of `--remote-host`, `--remote-port`, `--remote-path`, `--remote-php`, etc, by setting it in the created master file.
```vendor-dir/visay/syncontent/config/master/demo-014-007
--remote-host=10.10.10.37
--remote-port=2222
--remote-path=/home/user/neosbox
--remote-php=/opt/php-versions/php55/bin/php
```
......
localhost ansible_connection=local
[target]
remote ansible_ssh_host={{ HOST }} ansible_ssh_private_key_file=~/.ssh/id_rsa
remote ansible_ssh_host={{ HOST }} ansible_ssh_port={{ PORT }} ansible_ssh_private_key_file=~/.ssh/id_rsa
......@@ -49,7 +49,7 @@ if [ -z "${FRAMEWORK}" ]; then
exit 1
fi
# Read all arguments and parse into variable ${REMOTE_USER}, ${REMOTE_PATH} and ${REMOTE_HOST}
# Read all arguments and parse into variable ${REMOTE_USER}, ${REMOTE_PATH}, ${REMOTE_HOST} and ${REMOTE_PORT}
for ARGS in "$@"
do
case ${ARGS} in
......@@ -65,6 +65,10 @@ do
REMOTE_HOST="${ARGS#*=}"
shift
;;
-P=*|--remote-port=*)
REMOTE_PORT="${ARGS#*=}"
shift
;;
-t=*|--ansible-tags=*)
ANSIBLE_TAGS="--tags=${ARGS#*=}"
shift
......@@ -129,17 +133,39 @@ if [ -z "${REMOTE_HOST}" ]; then
fi
fi
# If remote port is not set, read it from config file
if [ -z "${REMOTE_PORT}" ]; then
if [ -f "${MASTER_FILE}" ]; then
IFS=$'\n'
for LINE in `cat ${MASTER_FILE}`
do
LINE=${LINE//[[:blank:]]/}
case ${LINE} in
-P=*|--remote-port=*)
REMOTE_PORT="${LINE#*=}"
shift
;;
esac
done
fi
fi
# If remote host cannot be found anywhere, fallback to default web server
if [ -z "${REMOTE_HOST}" ]; then
REMOTE_HOST="10.10.10.27"
fi
# If remote port cannot be found anywhere, fallback to default ssh port 22
if [ -z "${REMOTE_PORT}" ]; then
REMOTE_PORT="22"
fi
# Test connection to the server whether auto login is enabled
PING=`ssh -q -o "BatchMode=yes" ${REMOTE_USER}@${REMOTE_HOST} echo "OK"`
PING=`ssh -q -o "BatchMode=yes" ${REMOTE_USER}@${REMOTE_HOST} -p ${REMOTE_PORT} echo "OK"`
if [ "${PING}" != "OK" ]; then
echo -e ${RED}"-> Public key authentication failed!"${NC}
echo
echo -e ${BROWN}"Make sure you have auto login when running: ${WHITE}ssh ${REMOTE_USER}@${REMOTE_HOST}"${NC}
echo -e ${BROWN}"Make sure you have auto login when running: ${WHITE}ssh ${REMOTE_USER}@${REMOTE_HOST} -p ${REMOTE_PORT}"${NC}
echo
exit 1
fi
......@@ -214,7 +240,7 @@ if [ "${FRAMEWORK}" == "typo3" ]; then
exit 1
fi
if (ssh ${REMOTE_USER}@${REMOTE_HOST} "[ ! -f ${REMOTE_DUMP} ]"); then
if (ssh ${REMOTE_USER}@${REMOTE_HOST} -p ${REMOTE_PORT} "[ ! -f ${REMOTE_DUMP} ]"); then
echo -e ${RED}"-> Please make sure the dump file at ${REMOTE_DUMP} exists on remote server"${NC}
echo
exit 1
......@@ -222,7 +248,7 @@ if [ "${FRAMEWORK}" == "typo3" ]; then
fi
# Check if data directory exists at the remote path on the server
if (ssh ${REMOTE_USER}@${REMOTE_HOST} "[ ! -d ${REMOTE_PATH}/${DATA_DIR} ]"); then
if (ssh ${REMOTE_USER}@${REMOTE_HOST} -p ${REMOTE_PORT} "[ ! -d ${REMOTE_PATH}/${DATA_DIR} ]"); then
echo -e ${RED}"-> Directory '${REMOTE_PATH}/${DATA_DIR}' does not exist on the server running ${FRAMEWORK}"${NC}
echo
echo -e ${BROWN}"Check if your '--remote-path' config is set properly"${NC}
......@@ -232,7 +258,7 @@ fi
# Create dynamic inventory file
rm -f ${PACKAGE_DIR}/ansible/hosts.ini
sed "s/{{ HOST }}/${REMOTE_HOST}/g" ${PACKAGE_DIR}/ansible/hosts.ini.template > ${PACKAGE_DIR}/ansible/hosts.ini
sed "s/{{ HOST }}/${REMOTE_HOST}/g;s/{{ PORT }}/${REMOTE_PORT}/g" ${PACKAGE_DIR}/ansible/hosts.ini.template > ${PACKAGE_DIR}/ansible/hosts.ini
# Prepare all parameters for ansible
ANSIBLE_PARAMS="-i ${PACKAGE_DIR}/ansible/hosts.ini ${PACKAGE_DIR}/ansible/playbook.yml"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment