39 lines
1017 B
Bash
Executable File
39 lines
1017 B
Bash
Executable File
#!/usr/bin/env bash
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# Uses ansible-pull from a Python venv to create a LXD container
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
usage ()
|
|
{
|
|
echo "Uses ansible-pull from a Python venv to create a LXD container"
|
|
echo " Usage: $1 <new-container-name>"
|
|
}
|
|
|
|
is_in () {
|
|
[[ $2 =~ (^|[[:space:]])$1($|[[:space:]]) ]] && return 0 || return 1
|
|
}
|
|
|
|
CONTAINER="$1"
|
|
|
|
# Need a container name:
|
|
if [ -z "$CONTAINER" ]; then
|
|
usage "$0"
|
|
exit 1
|
|
fi
|
|
|
|
# Container cannot exist already:
|
|
ALLCONTAINERS=$(lxc ls -c n --format csv)
|
|
|
|
if is_in "$CONTAINER" "${ALLCONTAINERS}"; then
|
|
printf 'ERROR: %s\n' "A container with that name exists already" >&2
|
|
exit 2
|
|
fi
|
|
|
|
~/.venv/ansible/bin/ansible-pull \
|
|
--url ssh://git@gitea.agofer.net:22001/jegomez/ansible-role-odoo14-launch-container \
|
|
--extra-vars nombre=${CONTAINER} \
|
|
--vault-password-file ~/.vault_pass.txt \
|
|
--limit localhost,nginx \
|
|
--inventory hosts
|
|
|