KCLS Ansible-based brick manager + wizard
authorBill Erickson <berickxx@gmail.com>
Tue, 27 Feb 2018 16:13:06 +0000 (11:13 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Brick stop/start/deploy/etc actions managed by ansible.
Includes a wizard script to walk the user through the steps for each
action.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
21 files changed:
KCLS/admin-scripts/ansible/.gitignore [new file with mode: 0644]
KCLS/admin-scripts/ansible/README.adoc [new file with mode: 0644]
KCLS/admin-scripts/ansible/clusters/localhost.ini [new file with mode: 0644]
KCLS/admin-scripts/ansible/clusters/production.ini [new file with mode: 0644]
KCLS/admin-scripts/ansible/clusters/staging.ini [new file with mode: 0644]
KCLS/admin-scripts/ansible/clusters/testing.ini [new file with mode: 0644]
KCLS/admin-scripts/ansible/eg-brick-wizard.sh [new file with mode: 0755]
KCLS/admin-scripts/ansible/playbook.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/attach.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/deploy.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/detach.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/pinghost.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/starteg.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/startsip.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/startutil.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/startweb.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/stopeg.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/stopsip.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/stoputil.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/plays/stopweb.yml [new file with mode: 0644]
KCLS/admin-scripts/ansible/vars.yml [new file with mode: 0644]

diff --git a/KCLS/admin-scripts/ansible/.gitignore b/KCLS/admin-scripts/ansible/.gitignore
new file mode 100644 (file)
index 0000000..f1b6215
--- /dev/null
@@ -0,0 +1 @@
+credentials.yml
diff --git a/KCLS/admin-scripts/ansible/README.adoc b/KCLS/admin-scripts/ansible/README.adoc
new file mode 100644 (file)
index 0000000..ca63742
--- /dev/null
@@ -0,0 +1,78 @@
+= KCLS Ansible Cluster Manager
+
+== Synopsis
+
+[source,sh]
+-------------------------------------------------------------------------
+ansible-playbook --ask-vault-pass -i clusters/testing.ini playbook.yml \
+   -e stop_all=true                 \
+   -e eg_git_branch=release/2.12    \
+   -e deploy=true                   \
+   -e start_all=true                \
+   -e attach=true
+-------------------------------------------------------------------------
+
+See vars.yml for all supported actions.
+
+== Modes
+
+ * 'graceful' (default) mode operates on one server at a time and performs a 
+    graceful detach when a detach is needed.  Useful for "rolling" actions.
+
+ * 'quick' mode operates on multiple servers at a time does does not pause
+   between detaching and stopping services.  Useful for downtime deployments.
+
+== Inventory/Hosts
+
+ * See clusters/*.ini for inventory options.
+ * Hosts are grouped into bricks, sips, and utils.  Actions specific to
+   a given type of type of host (e.g. start_sip) are only performed on
+   hosts where the action applies.
+ * To limit to a specific server or set of servers:
+[source,sh]
+-------------------------------------------------------------------------
+ansible-playbook ... -l bricks
+ansible-playbook ... -l testing-brick02, # comma is required
+-------------------------------------------------------------------------
+
+== Credentials
+
+The value stored for ansible_ssh_user must have SSH keys and sudo access, 
+preferably requiring a sudo password.
+
+The playbook requires a credentials.yml file for managing remote servers.
+This file is not stored in the repository.  This file contains the remote 
+SSH user name and password.  
+
+This file also contains the Evergreen admin password, needed by start_util
+when starting marc_stream_importer.pl
+
+Ideally, this file will be encrypted using ansible vault.
+
+=== Create the file:
+
+* Create a new file in this directory called 'credentials.yml'
+* Define these variables:
+
+[source,yml]
+-------------------------------------------------------------------------
+ansible_ssh_user: remote_user_name
+ansible_sudo_pass: remote_user_pass
+eg_admin_pass: admin_pass
+-------------------------------------------------------------------------
+
+=== Encrypt the file (optional but recommended).
+
+[source,yml]
+-------------------------------------------------------------------------
+ansible-vault encrypt credentials.yml
+-------------------------------------------------------------------------
+
+* Run ansible-playbook with --ask-vault-pass or --vault-password-file to
+  decrypt the file at playbook run time.
+
+== Examples
+
+ansible-playbook --ask-vault-pass -i clusters/localhost.ini -e detach=true -e post_detach_sleep=1 playbook.yml
+ansible-playbook --vault-password-file ~/.ansible_kcls_vault -i clusters/localhost.ini -e detach=true -e post_detach_sleep=1 playbook.yml
+
diff --git a/KCLS/admin-scripts/ansible/clusters/localhost.ini b/KCLS/admin-scripts/ansible/clusters/localhost.ini
new file mode 100644 (file)
index 0000000..e84b20b
--- /dev/null
@@ -0,0 +1,15 @@
+# Localhost inventory
+
+[bricks]
+localhost
+
+[sips]
+localhost
+
+[utils]
+localhost
+
+[all:children]
+bricks
+sips
+utils
diff --git a/KCLS/admin-scripts/ansible/clusters/production.ini b/KCLS/admin-scripts/ansible/clusters/production.ini
new file mode 100644 (file)
index 0000000..7bae8f0
--- /dev/null
@@ -0,0 +1,25 @@
+# KCLS production cluster servers.
+# !! Note at time of writing all prod servers are pending deployment.
+
+[bricks]
+prod-vm-brick01
+prod-vm-brick02
+prod-vm-brick03
+prod-vm-brick04
+prod-vm-brick05
+prod-vm-brick06
+prod-vm-brick07
+
+[sips]
+prod-vm-sip01
+prod-vm-sip02
+prod-vm-sip03
+
+[utils]
+prod-vm-utility
+
+[all:children]
+bricks
+sips
+utils
+
diff --git a/KCLS/admin-scripts/ansible/clusters/staging.ini b/KCLS/admin-scripts/ansible/clusters/staging.ini
new file mode 100644 (file)
index 0000000..1a7377e
--- /dev/null
@@ -0,0 +1,17 @@
+# KCLS staging cluster servers
+
+[bricks]
+staging-brick01
+staging-brick02
+
+[sips]
+staging-sip01
+
+[utils]
+staging-utility
+
+[al:children]
+bricks
+sips
+utils
+
diff --git a/KCLS/admin-scripts/ansible/clusters/testing.ini b/KCLS/admin-scripts/ansible/clusters/testing.ini
new file mode 100644 (file)
index 0000000..0fbca55
--- /dev/null
@@ -0,0 +1,17 @@
+# KCLS testing cluster servers.
+
+[bricks]
+testing-brick01
+testing-brick02
+
+[sips]
+testing-sip01
+
+[utils]
+testing-utility
+
+[all:children]
+bricks
+sips
+utils
+
diff --git a/KCLS/admin-scripts/ansible/eg-brick-wizard.sh b/KCLS/admin-scripts/ansible/eg-brick-wizard.sh
new file mode 100755 (executable)
index 0000000..4d8311c
--- /dev/null
@@ -0,0 +1,142 @@
+#!/bin/bash
+set -euo pipefail
+CLUSTER="" 
+LIMIT_HOST=""
+SERVER=""
+YESNO=""
+BRANCH=""
+DEPLOY_MODE=""
+VAULT_PASSWORD_FILE=""
+EG_VERSION=""
+EG_SERIES=""
+ANSIBLE_COMMAND="ansible-playbook playbook.yml"
+
+function usage {
+    cat <<USAGE
+        $0 -p <vault-password-file>
+
+        Prompts for commands to run on Evergreen cluster servers and
+        executes the commands via ansible.
+    
+        Options:
+            -p <vault-password-file>
+                Full path to an ansible vault password file.  The user
+                will be prompted for the vault password when this option
+                is not specified.
+USAGE
+    exit
+}
+
+# returns true (exit stat 0) if we're likely working on bricks
+function might_be_brick {
+    if [ $CLUSTER != "localhost" ]; then
+        if [[ -z "$LIMIT_HOST" || $LIMIT_HOST = *"brick"* ]]; then
+            return 0;
+        fi;
+    fi;
+    return 1;
+}
+
+# return true (exit status 0) if YES was selected
+function yes_no_prompt {
+    PROMPT="$1"
+    ASSIGNMENT="$2"
+
+    printf "%-24s %s" "$PROMPT" "[y/N] "
+    read YESNO
+    if [ "$YESNO" = "y" ]; then
+        ANSIBLE_COMMAND="$ANSIBLE_COMMAND -e $ASSIGNMENT"
+        return 0;
+    fi;
+    return 1;
+}
+
+while getopts "p:h" opt; do
+    case $opt in
+        p) VAULT_PASSWORD_FILE="$OPTARG";;
+        h|*) usage;
+    esac
+done;
+
+
+if [ -n "$VAULT_PASSWORD_FILE" ]; then
+    ANSIBLE_COMMAND="$ANSIBLE_COMMAND --vault-password-file $VAULT_PASSWORD_FILE"
+else
+    ANSIBLE_COMMAND="$ANSIBLE_COMMAND --ask-vault-pass"
+fi
+
+echo -e "[l] localhost\n[t] testing\n[s] staging\n[p] production"
+echo -n "Cluster: " ; read CLUSTER_CODE
+
+case "$CLUSTER_CODE" in
+    "l") CLUSTER="localhost";;
+    "t") CLUSTER="testing";;
+    "s") CLUSTER="staging";;
+    "p") CLUSTER="production";;
+      *) echo "Cluster needed" && exit 1;;
+esac
+
+ANSIBLE_COMMAND="$ANSIBLE_COMMAND -i clusters/${CLUSTER}.ini" 
+
+if [ $CLUSTER != "localhost" ]; then
+    echo ""
+    echo "Optional: limit to a specific server or server group."
+    echo "For single servers, use ansible-style names with trailing commas."
+    echo 'Examples: "bricks" "testing-utility,"'
+    echo -n "Host or group: "; read LIMIT_HOST
+
+    if [ -n "$LIMIT_HOST" ]; then
+        ANSIBLE_COMMAND="$ANSIBLE_COMMAND -l $LIMIT_HOST"
+    fi
+fi;
+
+if might_be_brick; then
+    if yes_no_prompt "Detach bricks?" "detach=true"; then
+        if yes_no_prompt "Non-graceful detach?" "post_detach_sleep=0";
+            then true;
+        fi;
+    fi;
+fi;
+
+# note: "then true" satisfies strict error mode (see top of file)
+if yes_no_prompt "Stop services?" "stop_all=true"; then true; fi;
+
+if yes_no_prompt "Deploy code?" "deploy=true"; then
+    echo -n "Branch name or empty for git-pull: "; read BRANCH;
+
+    if [ -n "$BRANCH" ]; then
+        ANSIBLE_COMMAND="$ANSIBLE_COMMAND -e eg_git_branch=$BRANCH"
+    else
+        ANSIBLE_COMMAND="$ANSIBLE_COMMAND -e eg_git_pull=true"
+    fi
+
+    echo -n "Evergreen series  (e.g. kcls-2.12): "; read EG_SERIES;
+    echo -n "Evergreen version (eg. kcls-2.12-2.1): "; read EG_VERSION;
+    ANSIBLE_COMMAND="$ANSIBLE_COMMAND -e eg_stamp_id=$EG_VERSION -e eg_series_id=$EG_SERIES"
+fi;
+
+if yes_no_prompt "Start services?" "start_all=true"; then true; fi;
+
+if might_be_brick; then
+    if yes_no_prompt "Attach bricks?" "attach=true"; then true; fi;
+fi;
+
+if [ $CLUSTER != "localhost" ]; then
+    if yes_no_prompt "Operate on multiple hosts (max 3 per group) at a time?" "serial=3";
+        then true; 
+    fi;
+fi;
+
+
+echo ""
+echo "------------------------------------------------------"
+echo "$ANSIBLE_COMMAND"
+echo "------------------------------------------------------"
+echo ""
+echo -n "Execute final command? [Y/n] "
+read YESNO
+if [ "$YESNO" = "y" -o -z "$YESNO" ]; then
+    $ANSIBLE_COMMAND;
+fi;
+
+
diff --git a/KCLS/admin-scripts/ansible/playbook.yml b/KCLS/admin-scripts/ansible/playbook.yml
new file mode 100644 (file)
index 0000000..a0242f7
--- /dev/null
@@ -0,0 +1,82 @@
+# KCLS Evergreen deployment ansible script
+# Author: Bill Erickson <berickxx@gmail.com>
+#
+# KCLS Evergreen Deployment Ansible Playbook
+
+- hosts: 'bricks'
+  serial: '{{serial}}'
+  vars_files:
+    - vars.yml
+    - credentials.yml
+  tasks:
+    - include: plays/pinghost.yml
+      when: ping_host
+    - block:
+      - include: plays/detach.yml
+      - include: plays/stopweb.yml
+      when: stop_web or stop_all
+    - include: plays/stopeg.yml
+      when: stop_eg or stop_all
+    - include: plays/deploy.yml
+      when: deploy
+    - include: plays/starteg.yml
+      when: start_eg or start_all
+    - include: plays/startweb.yml
+      when: start_web or start_all
+    - include: plays/attach.yml
+      when: attach
+
+- hosts: 'sips'
+  serial: '{{serial}}'
+  vars_files:
+    - vars.yml
+    - credentials.yml
+  tasks:
+    - include: plays/pinghost.yml
+      when: ping_host
+    - include: plays/stopsip.yml
+      when: stop_sip or stop_all
+    - include: plays/stopeg.yml
+      when: 
+        - stop_eg or stop_all
+        # Avoid running duplicate commands on single-server setups.
+        # e.g. dev servers
+        - "'bricks' not in group_names"
+    - include: plays/deploy.yml
+      when: 
+        - deploy
+        - "'bricks' not in group_names"
+    - include: plays/starteg.yml
+      when: 
+        - start_eg or start_all
+        - "'bricks' not in group_names"
+    - include: plays/startsip.yml
+      when: start_sip or start_all
+
+- hosts: 'utils'
+  vars_files:
+    - vars.yml
+    - credentials.yml
+  tasks:
+    - include: plays/pinghost.yml
+      when: ping_host
+    - include: plays/stoputil.yml
+      when: stop_util or stop_all
+    - include: plays/stopeg.yml
+      when: 
+        - stop_eg or stop_all
+        - "'bricks' not in group_names"
+        - "'sips' not in group_names"
+    - include: plays/deploy.yml
+      when: 
+        - deploy
+        - "'bricks' not in group_names"
+        - "'sips' not in group_names"
+    - include: plays/starteg.yml
+      when: 
+        - start_eg or start_all
+        - "'bricks' not in group_names"
+        - "'sips' not in group_names"
+    - include: plays/startutil.yml
+      when: start_util or start_all
+
diff --git a/KCLS/admin-scripts/ansible/plays/attach.yml b/KCLS/admin-scripts/ansible/plays/attach.yml
new file mode 100644 (file)
index 0000000..f062c2e
--- /dev/null
@@ -0,0 +1,14 @@
+
+- name: 'Checking for detached ping file: {{ping_file}}-'
+  stat:
+    path: '{{ping_file}}-'
+  register: ping_file_stat
+- block:
+  - name: Moving Ping File
+    become: true
+    become_user: '{{opensrf_user}}'
+    command: 'mv {{ping_file}}- {{ping_file}}'
+  when: 
+    - ping_file_stat.stat.exists == True
+
+
diff --git a/KCLS/admin-scripts/ansible/plays/deploy.yml b/KCLS/admin-scripts/ansible/plays/deploy.yml
new file mode 100644 (file)
index 0000000..5fb9427
--- /dev/null
@@ -0,0 +1,131 @@
+
+- block:
+  - name: 'Checkout Evergreen Branch {{eg_git_branch}}'
+    become: true
+    become_user: '{{opensrf_user}}'
+    git:
+      repo: "{{eg_git_repository}}"
+      dest: "{{repo_base}}/Evergreen"
+      remote: "{{eg_git_remote}}"
+      version: "{{eg_git_branch}}"
+      force: "{{eg_git_force}}"
+    when: eg_git_branch != ''
+  - name: 'Git Pull'
+    become: true
+    become_user: '{{opensrf_user}}'
+    shell: cd {{repo_base}}/Evergreen && git pull
+    when: 
+      # when a branch is specified a pull is unnecessary
+     - eg_git_pull
+     - eg_git_branch == ''
+  - name: Set ownership of {{repo_base}}/Evergreen to {{opensrf_user}}
+    become: true
+    file: dest={{repo_base}}/Evergreen owner={{opensrf_user}} group={{opensrf_user}} recurse=yes
+  - name: Configure Evergreen
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: >
+      cd {{repo_base}}/Evergreen 
+      && autoreconf -i 
+      && ./configure --prefix={{eg_install_path}} --sysconfdir={{eg_install_path}}/conf 
+  - name: Make Clean
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: >
+      cd {{repo_base}}/Evergreen 
+      && make clean
+    when: make_clean
+  - name: Build Evergreen
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: >
+      cd {{repo_base}}/Evergreen 
+      && make
+  - name: Install Evergreen
+    become: true
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: >
+      cd {{repo_base}}/Evergreen 
+      && make STAFF_CLIENT_STAMP_ID={{eg_stamp_id}} STAFF_CLIENT_VERSION={{eg_stamp_id}} install
+  - name: Set ownership of {{repo_base}}/Evergreen to {{opensrf_user}}
+    become: true
+    file: dest={{repo_base}}/Evergreen owner={{opensrf_user}} group={{opensrf_user}} recurse=yes
+  - name: Modify Ownership of {{eg_install_path}} to {{opensrf_user}}
+    # Changes ownership of most files back to opensrf after make-install,
+    # skipping directories that are often mounted as NFS shares.
+    become: true
+    file: 
+      owner: '{{opensrf_user}}'
+      group: '{{opensrf_user}}'
+      recurse: yes
+      dest: '{{item.dest}}'
+    with_items: 
+      - {dest: '{{eg_install_path}}/conf'}
+      - {dest: '{{eg_install_path}}/include'}
+      - {dest: '{{eg_install_path}}/lib'}
+      - {dest: '{{eg_install_path}}/share'}
+      - {dest: '{{eg_install_path}}/var/cgi-bin'}
+      - {dest: '{{eg_install_path}}/var/lock'}
+      - {dest: '{{eg_install_path}}/var/log'}
+      - {dest: '{{eg_install_path}}/var/run'}
+      - {dest: '{{eg_install_path}}/var/templates'}
+      - {dest: '{{eg_install_path}}/var/templates_kcls'}
+      - {dest: '{{eg_install_path}}/var/updates'}
+      - {dest: '{{eg_install_path}}/var/xsl'}
+      - {dest: '{{eg_install_path}}/var/web/xul'}
+      - {dest: '{{eg_install_path}}/var/web/js'}
+      - {dest: '{{eg_install_path}}/var/web/css'}
+      - {dest: '{{eg_install_path}}/var/web/images'}
+      - {dest: '{{eg_install_path}}/var/web/audio'}
+      - {dest: '{{eg_install_path}}/var/web/conify'}
+      - {dest: '{{eg_install_path}}/var/web/opac'}
+      - {dest: '{{eg_install_path}}/var/web/reports'}
+  - name: Create XUL Current Symlink
+    become: true
+    become_user: '{{opensrf_user}}'
+    file:
+      state: link
+      src: "{{eg_install_path}}/var/web/xul/{{eg_stamp_id}}"
+      dest: "{{eg_install_path}}/var/web/xul/current"
+  - name: Create XUL Series Symlink
+    become: true
+    become_user: '{{opensrf_user}}'
+    file:
+      state: link
+      src: "{{eg_install_path}}/var/web/xul/{{eg_stamp_id}}"
+      dest: "{{eg_install_path}}/var/web/xul/{{eg_series_id}}"
+  - name: Create XUL Server Symlink
+    become: true
+    become_user: '{{opensrf_user}}'
+    file:
+      state: link
+      src: "{{eg_install_path}}/var/web/xul/current/server"
+      dest: "{{eg_install_path}}/var/web/xul/server"
+  - name: Copy Additional Repo Files Into Place
+    # Copy additional files into place.  Some of these the EG installer
+    # does not copy and others are specific to KCLS.
+    become: true
+    become_user: '{{opensrf_user}}'
+    shell: |
+      cp -r {{repo_base}}/Evergreen/KCLS/openils/var/templates_kcls {{eg_install_path}}/var/;
+      mkdir -p {{eg_install_path}}/var/cgi-bin/ezproxy/;
+      cp {{repo_base}}/Evergreen/Open-ILS/examples/remoteauth.cgi {{eg_install_path}}/var/cgi-bin/ezproxy/;
+      cp {{repo_base}}/Evergreen/KCLS/utility-scripts/send-print-notices.pl {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/KCLS/monitor-scripts/* {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/KCLS/admin-scripts/* {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/support-scripts/edi_fetcher.pl {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/support-scripts/edi_pusher.pl {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/edi_translator/edi_webrick.rb {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/edi_translator/edi_webrick.bash {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/support-scripts/marc_stream_importer.pl {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/support-scripts/oils_header.pl {{eg_install_path}}/bin/;
+      cp {{repo_base}}/Evergreen/Open-ILS/src/support-scripts/set_pbx_holidays.pl {{eg_install_path}}/bin/;
+
+
diff --git a/KCLS/admin-scripts/ansible/plays/detach.yml b/KCLS/admin-scripts/ansible/plays/detach.yml
new file mode 100644 (file)
index 0000000..f51c938
--- /dev/null
@@ -0,0 +1,16 @@
+
+- name: 'Checking for ping file: {{ping_file}}'
+  stat:
+    path: '{{ping_file}}'
+  register: ping_file_stat
+- block:
+  - name: Moving Ping File
+    become: true
+    become_user: '{{opensrf_user}}'
+    command: 'mv {{ping_file}} {{ping_file}}-'
+  - name: 'Post-Detach Sleep {{post_detach_sleep}}'
+    pause: seconds='{{post_detach_sleep}}'
+  when: 
+    - ping_file_stat.stat.exists == True
+
+
diff --git a/KCLS/admin-scripts/ansible/plays/pinghost.yml b/KCLS/admin-scripts/ansible/plays/pinghost.yml
new file mode 100644 (file)
index 0000000..e32a418
--- /dev/null
@@ -0,0 +1,6 @@
+# Simple proof-of-life / ping test to confirm server communication
+- name: Cat Hostname File
+  shell: /bin/cat /etc/hostname
+  register: hostname_file
+- debug: msg="Talking to host {{hostname_file.stdout | quote}}"
+
diff --git a/KCLS/admin-scripts/ansible/plays/starteg.yml b/KCLS/admin-scripts/ansible/plays/starteg.yml
new file mode 100644 (file)
index 0000000..0b55024
--- /dev/null
@@ -0,0 +1,15 @@
+- block:
+  - name: Starting Evergreen Services
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: osrf_control --localhost --start-all
+  - name: 'Post-Evergreen Startup Sleep {{post_start_sleep}}'
+    pause: seconds='{{post_start_sleep}}'
+  - name: Running Autogen
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: autogen.sh
diff --git a/KCLS/admin-scripts/ansible/plays/startsip.yml b/KCLS/admin-scripts/ansible/plays/startsip.yml
new file mode 100644 (file)
index 0000000..706badc
--- /dev/null
@@ -0,0 +1,12 @@
+- name: Starting SIP
+  become: true
+  become_user: '{{opensrf_user}}'
+  environment:
+    PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+  # poll/async to give oils_ctl.sh enough time to background the SIP
+  # process.  Otherwise, the ansible process starting SIP will exit and
+  # take SIP out with it.
+  poll: 0
+  async: 1
+  shell: OSRF_ADOPT_SYSLOG=1 SIP_LOG_IDENT=SIP OSRF_LOG_CLIENT=1 oils_ctl.sh -a start_sip -l /tmp/sip.log 
+
diff --git a/KCLS/admin-scripts/ansible/plays/startutil.yml b/KCLS/admin-scripts/ansible/plays/startutil.yml
new file mode 100644 (file)
index 0000000..d6f5707
--- /dev/null
@@ -0,0 +1,36 @@
+
+- name: Removing Reporter Lock File
+  become: true
+  become_user: '{{opensrf_user}}'
+  file: state=absent path='{{reporter_lockfile}}'
+- name: Starting Reporter
+  become: true
+  become_user: '{{opensrf_user}}'
+  environment:
+    PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+  poll: 0
+  async: 1
+  shell: '/openils/bin/clark-kent.pl -d -c {{reporter_concurrent}} --statement-timeout {{reporter_statement_timeout}}'
+- name: Starting Z39.50
+  become: true
+  poll: 0
+  async: 1
+  shell: 'cd {{repo_base}}/Evergreen/KCLS/admin-scripts && ./eg-zoom-control.sh start'
+- name: Starting Connexion
+  become: true
+  poll: 0
+  async: 1
+  shell: 'cd {{repo_base}}/Evergreen/KCLS/admin-scripts && ./eg-marc-stream-control.sh start {{eg_admin_pass}}'
+- name: Check for running EDI Webrick
+  ignore_errors: yes
+  changed_when: false
+  shell: ps ax | grep edi_webrick | grep -v grep
+  register: webrick_pid_status
+- name: Start EDI Webrick
+  become: true
+  become_user: '{{opensrf_user}}'
+  poll: 0
+  async: 1
+  shell: 'cd {{eg_install_path}}/bin && ./edi_webrick.bash'
+  when: webrick_pid_status | failed
+
diff --git a/KCLS/admin-scripts/ansible/plays/startweb.yml b/KCLS/admin-scripts/ansible/plays/startweb.yml
new file mode 100644 (file)
index 0000000..6e62e92
--- /dev/null
@@ -0,0 +1,15 @@
+
+- block: 
+  - name: Starting Websockets
+    become: true
+    service: name=websocketd-osrf state=started
+  - name: Starting Apache
+    become: true
+    service: name=apache2 state=started
+  - name: Starting NGINX
+    become: true
+    service: name=nginx state=started
+  - name: 'Post-Web Startup Sleep {{post_web_sleep}}'
+    pause: seconds='{{post_web_sleep}}'
+    when: attach
+
diff --git a/KCLS/admin-scripts/ansible/plays/stopeg.yml b/KCLS/admin-scripts/ansible/plays/stopeg.yml
new file mode 100644 (file)
index 0000000..5821394
--- /dev/null
@@ -0,0 +1,20 @@
+
+- block:
+  - name: Stopping Evergreen Services
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: osrf_control --localhost --fast-shutdown-all
+  - name: 'Post-Web stop-EG sleep {{post_stop_eg_sleep}}'
+    pause: seconds='{{post_stop_eg_sleep}}'
+  - name: Force-killing Any Remaining EG Services
+    # Generally this won't be necessary, since the shutdown above should
+    # cover it. Run this to cover any hiccups where services are left
+    # dangling, which has happened a time or two.
+    become: true
+    become_user: '{{opensrf_user}}'
+    environment:
+      PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+    shell: osrf_control --localhost --kill-with-fire
+
diff --git a/KCLS/admin-scripts/ansible/plays/stopsip.yml b/KCLS/admin-scripts/ansible/plays/stopsip.yml
new file mode 100644 (file)
index 0000000..1c01c5f
--- /dev/null
@@ -0,0 +1,6 @@
+- name: Stopping SIP
+  become: true
+  become_user: '{{opensrf_user}}'
+  environment:
+    PATH: "{{ansible_env.PATH}}:{{eg_install_path}}/bin"
+  shell: oils_ctl.sh -a stop_sip
diff --git a/KCLS/admin-scripts/ansible/plays/stoputil.yml b/KCLS/admin-scripts/ansible/plays/stoputil.yml
new file mode 100644 (file)
index 0000000..fec9543
--- /dev/null
@@ -0,0 +1,25 @@
+
+- name: 'Checking for reporter lock file {{reporter_lockfile}}'
+  stat:
+    path: '{{reporter_lockfile}}'
+  register: reporter_lockfile_stat
+- block:
+  - name: Read Report Lock File PID
+    # note: lookup('file', ...) does not read remote files
+    shell: 'cat {{reporter_lockfile}}'
+    register: reporter_pid
+  - name: 'Stopping Reporter pid={{reporter_pid.stdout}}'
+    become: true
+    become_user: '{{opensrf_user}}'
+    shell: 'kill {{reporter_pid.stdout}}'
+    when: reporter_pid.stdout != ''
+  when: 
+    - reporter_lockfile_stat.stat.exists == True
+- name: Stopping Z39.50
+  become: true
+  shell: 'cd {{repo_base}}/Evergreen/KCLS/admin-scripts && ./eg-zoom-control.sh stop'
+- name: Stopping Connexion
+  become: true
+  shell: 'cd {{repo_base}}/Evergreen/KCLS/admin-scripts && ./eg-marc-stream-control.sh stop'
+
+
diff --git a/KCLS/admin-scripts/ansible/plays/stopweb.yml b/KCLS/admin-scripts/ansible/plays/stopweb.yml
new file mode 100644 (file)
index 0000000..1b57400
--- /dev/null
@@ -0,0 +1,14 @@
+# Start with WebSockets because it supports graceful 
+# shutdown of open connections
+
+- block:
+  - name: Stopping Websockets
+    become: true
+    service: name=websocketd-osrf state=stopped
+  - name: Stopping Apache
+    become: true
+    service: name=apache2 state=stopped
+  - name: Stopping NGINX
+    become: true
+    service: name=nginx state=stopped
+
diff --git a/KCLS/admin-scripts/ansible/vars.yml b/KCLS/admin-scripts/ansible/vars.yml
new file mode 100644 (file)
index 0000000..4d33483
--- /dev/null
@@ -0,0 +1,52 @@
+# Deployment commands ---------------------------------------------------
+
+# Deployment Options
+# num servers to process at a time
+serial: 1
+# detach bricks gracefully?
+ping_host: false
+stop_eg: false
+stop_web: false
+stop_sip: false
+stop_util: false
+stop_all: false
+deploy: false
+start_eg: false
+start_web: false
+start_sip: false
+start_util: false
+start_all: false
+attach: false
+
+
+# post-action sleeps
+post_detach_sleep: 30
+post_start_sleep: 20
+post_web_sleep: 20
+post_stop_eg_sleep: 10
+
+# Deployment variables
+ping_file: '{{web_base}}/ping.txt'
+
+reporter_lockfile: '/tmp/reporter-LOCK'
+reporter_concurrent: 3
+reporter_statement_timeout: 360
+
+opensrf_user: opensrf
+repo_base: '/home/{{opensrf_user}}'
+eg_install_path: /openils
+web_base: '{{eg_install_path}}/var/web'
+osrf_git_repository: git://git.evergreen-ils.org/OpenSRF.git
+osrf_git_remote: origin
+osrf_git_branch: rel_2_5
+osrf_git_force: true
+# kcls-evergreen is an ~/.ssh/config Host entry on KCLS servers
+eg_git_repository: kcls-evergreen:kcls/Evergreen.git
+eg_git_remote: kcls
+eg_git_branch: ''
+eg_git_force: true
+eg_git_pull: false
+eg_series_id: kcls-2.12
+eg_stamp_id: kcls-2.12-3
+make_clean: false
+