Browse Source

+ probes to use env vars for lxc projects

master
Raptor Dimti Garuda 3 weeks ago
parent
commit
d9232999ca
  1. 2
      .gitignore
  2. 2
      ansible.cfg.example
  3. 13
      envs/lxc/server/lxc.env.example
  4. 1
      group_vars/all.yml
  5. 67
      run-lxc-playbook.sh

2
.gitignore

@ -1,3 +1,3 @@
*.retry
.idea
/secret
/ansible.cfg

2
ansible.cfg → ansible.cfg.example

@ -1,3 +1,3 @@
[defaults]
inventory=./hosts
group_vars=./group_vars
group_vars=./group_vars

13
envs/lxc/server/lxc.env.example

@ -0,0 +1,13 @@
SERVER=proxmox_host
LXC_HOST=project_lxc_container
PLAYBOOK=nginx-site
# That is a project name and name of the HOME USER
# @see group_vars/all.yml
SITE_NAME=project_name
DOMAIN_NAME=project_domain_name
DATABASE_NAME=project_name

1
group_vars/all.yml

@ -8,6 +8,5 @@ keyring__keyserver: hkp://keyserver.ubuntu.com:80
secret__levels: '.'
site_name: '{{ initial_site_name | d(lxc_host) }}'
home_user: '{{ (ansible_user != "root") | ternary(ansible_user, site_name) }}'
...

67
run-lxc-playbook.sh

@ -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
Loading…
Cancel
Save