Commit 5cca46fe by John Jarvis

adding role for ansible bootstrap

parent d080287d
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Defaults for role ansible, an ansible role to install ansible
#
#
# OS packages
#
ansible_debian_pkgs:
- python-pip
- python-apt
- git-core
- build-essential
- python-dev
- libxml2-dev
- libxslt-dev
- curl
ansible_app_dir: "{{ COMMON_APP_DIR }}/ansible"
ansible_code_dir: "{{ ansible_app_dir }}/ansible"
ansible_data_dir: "{{ COMMON_DATA_DIR }}/ansible"
ansible_venvs_dir: "{{ ansible_app_dir }}/venvs"
ansible_venv_dir: "{{ ansible_venvs_dir }}/ansible"
ansible_venv_bin: "{{ ansible_venv_dir }}/bin"
ansible_user: "ansible"
ansible_source_repo: https://github.com/ansible/ansible.git
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Role includes for role ansible
---
dependencies:
- supervisor
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
# Tasks for role ansible
#
# Overview:
#
# This is an ansible role that installs ansible :)
# The purpose is to install ansible on a server so
# that it can be updated locally.
#
# This role will also drop some helper scripts that
# for running ansible tasks
#
# Example play:
#
#
#
- name: ansible | create application user
user: >
name="{{ ansible_user }}"
home="{{ ansible_app_dir }}"
createhome=no
shell=/bin/false
- name: ansible | create ansible app and venv dir
file: >
path="{{ item }}"
state=directory
owner="{{ ansible_user }}"
group="{{ common_web_group }}"
with_items:
- "{{ ansible_app_dir }}"
- "{{ ansible_venvs_dir }}"
- name: ansible | install a bunch of system packages on which ansible relies
apt: pkg={{','.join(ansible_debian_pkgs)}} state=present
- name: ansible | git checkout ansible repo into ansible_code_dir
git: dest={{ ansible_code_dir }} repo={{ ansible_source_repo }} version={{ ansible_version }}
sudo_user: "{{ ansible_user }}"
- name : ansible | install ansible venv requirements
pip: requirements="{{ ansible_requirements_file }}" virtualenv="{{ ansible_venv_dir }}" state=present
sudo_user: "{{ ansible_user }}"
- name: ansible | create update script
template: >
dest={{ ansible_app_dir}}/update
src=update owner=ansible group=ansible mode=755
- name: edxapp | create a symlink for update.sh
file: >
src={{ ansible_app_dir }}/update
dest={{ COMMON_BIN_DIR }}/update
state=link
#!/usr/bin/env bash
# This script runs ansible locally
set -e
usage() {
SAVE_IFS=$IFS
IFS=","
cat<<EO
Usage: $PROG <repo> <version>
-v add verbosity to ansible run
-h this
<repo> - must be one of [${!repos_to_cmd[*]}]
<version> - can be a commit or tag
EO
IFS=$SAVE_IFS
}
declare -A repos_to_cmd
ansible_cmd="ansible-playbook -c local -vvvv --tags deploy"
repos_to_cmd["edx-platform"]="$ansible_cmd edxapp.yml -e 'edx_platform_version=$2'"
repos_to_cmd["xqueue"]="$ansible_cmd xqueue.yml -e 'xqueue_version=$2'"
repos_to_cmd["forums"]="$ansible_cmd forums.yml -e 'forum_version=$2'"
repos_to_cmd["xserver"]="$ansible_cmd forums.yml -e 'xserver_version=$2'"
repos_to_cmd["ease"]="$ansible_cmd discern.yml -e 'discern_ease_version=$2' && $ansible_cmd ora.yml -e 'ora_ease_version=$2'"
repos_to_cmd["discern"]="$ansible_cmd discern.yml -e 'discern_version=$2'"
repos_to_cmd["edx-ora"]="$ansible_cmd ora.yml -e 'ora_version=$2'"
PROG=${0##*/}
while getopts "vh" opt; do
case $opt in
v)
verbose="-vvv"
shift
;;
h)
usage
exit 0
;;
esac
done
if [[ -z ${repos_to_cmd[$1]} ]]; then
echo
echo "ERROR: Invalid repo name"
usage
exit 1
fi
if [[ -z $2 ]]; then
echo
echo "ERROR: You must specify a commit or tag"
usage
exit 1
fi
cd {{ ansible_code_dir }}/playbooks/edx-east
eval "sudo ${repos_to_cmd["$1"]} $verbose"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment