ansible-vm-init 692 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash

# Log file path
LOGFILE="/root/ansible-vm-init.log"

log(){
  message=$1
  echo "$(date): $message" >> $LOGFILE
}

start(){
  # Initialize VM with ansible
  log "Initializing VM with ansible"
  ansible-playbook -i "localhost," -c local /var/www/okeanos-LoD/webapp/ansible/playbooks/image-configure.yml --tags "image-configure" >> $LOGFILE 2>&1
  retVal=$?
  if [ $retVal -eq 0 ]
  then
    log "Ansible VM initialization successful"
    rm /etc/init.d/ansible-vm-init
    update-rc.d ansible-vm-init remove
  else
    log "Ansible VM initialization failed with return value $retVal"
  fi

  return 0
}

case "$1" in
  start)
    start
    ;;
  *)
    echo "Usage: $0 start"
esac