I got this idea about using deploy scripts in the same way developer use ansible playbooks. I know is far from ideal, but I was able to make it work for my personal use.
So, the basics: Send a directory, execute a script in it, remove the directory when done.
For the future:
- apt utils
- service utils
- run on multiple machines
- populate the env with host facts (like ansible host facts)
For example, we could have a directory with a bash script and different provision files, in the same directory.
$ ls provision/
bootstrap.sh
nginx.conf
nginx.mydomain.conf
We can run bootstrap.sh
in a remote server, and send all the directory so the provision files will work the same as running them locally.
tar cpf - provision/ | ssh [email protected] "tar xpf - -C /tmp && cd /tmp/provision && bash /tmp/provision/bootstrap.sh && rm -rf /tmp/provision"
We can also make it a single function:
function play () {
local remote=${2}
local script=${1}
local directory=$(dirname ${script})
tar cpf - ${directory}/ | ssh -t ${remote} "
tar xpf - -C /tmp &&
cd /tmp/${directory} &&
bash /tmp/${script} &&
rm -rf /tmp/${directory}
"
}
Use like this:
$ play provision/bootstrap.sh [email protected]
* base server provisioned [Ok]
* Installing tools [Ok]
$ play application-server/bootstrap.sh [email protected]
* Installing python3 [Ok]
* Creating virtualenv [Ok]
$ play database-server/bootstrap.sh [email protected]
* Installing postgresql [Ok]
* Creating users [Ok]
* Creating databases [Ok]
All I can say is that I love the simplicity of this idea. +1