Commit 690038ac by John Jarvis

Merge pull request #319 from edx/jarv/provision

Jarv/provision
parents 4cb25800 7edc4201
......@@ -6,3 +6,4 @@
jinja2_extensions=jinja2.ext.do
hash_behaviour=merge
host_key_checking = False
- name: Configure instance(s)
hosts: all
sudo: True
gather_facts: True
vars:
openid_workaround: True
roles:
- edxapp
- name: Configure instance(s)
hosts: tag_Name_edx-continuous-integration
hosts: all
sudo: True
gather_facts: True
vars:
......
- name: Create ec2 instance
hosts: localhost
connection: local
gather_facts: False
roles:
- role: launch_ec2
keypair: "{{ keypair }}"
instance_type: "{{ instance_type }}"
security_group: "{{ security_group }}"
ami_image: "{{ ami }}"
region: "{{ region }}"
instance_tags: "{{ instance_tags }}"
root_ebs_size: "{{ root_ebs_size }}"
dns_name: "{{ dns_name }}"
dns_zone: "{{ dns_zone }}"
- name: Configure instance(s)
hosts: launched
sudo: True
gather_facts: True
roles:
# gh_users hash must be passed
# in as a -e variable
- gh_users
../inventory.ini
\ No newline at end of file
../library
\ No newline at end of file
......@@ -2,8 +2,9 @@
# This should only have variables
# that are applicable to all edX roles
storage_base_dir: /mnt
app_base_dir: /opt/wwc
log_base_dir: /mnt/logs
log_base_dir: "{{ storage_base_dir }}/logs"
venv_dir: /opt/edx
os_name: ubuntu
......
......@@ -10,6 +10,14 @@
- pre_install
- update
- name: common | Create the base directory for storage
file: >
path={{ storage_base_dir }}
state=directory
owner=root
group=root
mode=0755
- name: common | Create application root
# In the future consider making group edx r/t adm
file: path={{ app_base_dir }} state=directory owner=root group=adm mode=2775
......
......@@ -154,7 +154,7 @@ generic_env_config: &edxapp_generic_env
WIKI_ENABLED: true
SYSLOG_SERVER: $EDXAPP_SYSLOG_SERVER
SITE_NAME: $EDXAPP_SITE_NAME
LOG_DIR: '/mnt/logs/edx'
LOG_DIR: "{{ storage_base_dir }}/logs/edx"
MEDIA_URL: $EDXAPP_MEDIA_URL
ANALYTICS_SERVER_URL: $EDXAPP_ANALYTICS_SERVER_URL
FEEDBACK_SUBMISSION_EMAIL: $EDXAPP_FEEDBACK_SUBMISSION_EMAIL
......@@ -293,75 +293,32 @@ sandbox_post_requirements: "{{ edx_platform_code_dir }}/requirements/edx-sandbo
install_sandbox_reqs_into_regular_venv: true
lms_debian_pkgs:
- apparmor-utils
- aspell
# for compiling the virtualenv
# (only needed if wheel files aren't available)
- build-essential
- curl
- dvipng
- fabric
- g++
- gcc
- gfortran
- ghostscript
- github-cli
- graphviz
- s3cmd
- pkg-config
- graphviz-dev
- gunicorn
- inoticoming
- ipython
- libcrypt-ssleay-perl
- libcurl4-openssl-dev
- libdigest-sha-perl
- libfreetype6-dev
- libgeos-dev
- libgraphviz-dev
- libjpeg8-dev
- liblapack-dev
- liblwp-protocol-https-perl
- graphviz
- libmysqlclient-dev
- libnet-amazon-ec2-perl
- libpng12-dev
- libreadline-dev
- libreadline6-dev
- libssl-dev
- libswitch-perl
- libwww-perl
- libxml++2.6-dev
# for scipy, do not install
# libopenblas-base, it will cause
# problems for numpy
- gfortran
- libatlas3gf-base
- liblapack-dev
- g++
- libxml2-dev
- libxml2-utils
- libxslt1-dev
- lynx-cur
- maven2
- mongodb-clients
- mysql-client
# apparmor
- apparmor-utils
# misc
- curl
- ipython
- npm
- ntp
- openjdk-7-jdk
- openjdk-7-jre
- pep8
- perl
- pkg-config
- postfix
- pylint
- python-boto
- python-coverage-test-runner
- python-django-nose
- python-jenkins
- python-nose
- python-nosexcover
- python-numpy
- python-pip
- python-scipy
- rake
- reprepro
- rsyslog
- rubygems
- sqlite3
- super
- vagrant
- yui-compressor
- zip
- zlib1g-dev
# for shapely
- libgeos-dev
# Ruby Specific Vars
ruby_base: /opt/www
......
......@@ -5,6 +5,7 @@
---
- name: create cms application config
template: src=cms.env.json.j2 dest=$app_base_dir/cms.env.json mode=640 owner=www-data group=adm
notify: restart edxapp
tags:
- cms-env
- cms
......@@ -12,6 +13,7 @@
- name: create cms auth file
template: src=cms.auth.json.j2 dest=$app_base_dir/cms.auth.json mode=640 owner=www-data group=adm
notify: restart edxapp
tags:
- cms-env
- cms
......
......@@ -5,12 +5,14 @@
---
- name: create lms application config
template: src=lms-preview.env.json.j2 dest=$app_base_dir/lms-preview.env.json mode=640 owner=www-data group=adm
notify: restart edxapp
tags:
- lms-preview
- lms-preview-env
- name: create lms auth file
template: src=lms-preview.auth.json.j2 dest=$app_base_dir/lms-preview.auth.json mode=640 owner=www-data group=adm
notify: restart edxapp
tags:
- lms-preview
- lms-preview-env
......
---
- name: create lms application config
template: src=lms.env.json.j2 dest=$app_base_dir/lms.env.json mode=640 owner=www-data group=adm
notify: restart edxapp
tags:
- lms
- lms-env
......@@ -8,6 +9,7 @@
- name: create lms auth file
template: src=lms.auth.json.j2 dest=$app_base_dir/lms.auth.json mode=640 owner=www-data group=adm
notify: restart edxapp
tags:
- lms
- lms-env
......
---
edxlocal_debian_pkgs:
- pymongo
- python-mysqldb
- mysql-server-5.5
- postfix
......@@ -11,14 +11,8 @@
# http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.62.tar.gz
#
---
- name: edxlocal | install python-pymongo (req for ansible)
pip: name=pymongo
- name: edxlocal | install python-mysqldb (req for ansible)
apt: pkg=python-mysqldb state=present
- name: edxlocal | install mysql server and recommends
apt: pkg=mysql-server-5.5 state=present install_recommends=yes
- name: edxlocal| install packages needed for single server
apt: pkg={{','.join(edxlocal_debian_pkgs)}} install_recommends=yes state=present
- name: edxlocal | create a database for edxapp
mysql_db: >
......@@ -38,17 +32,32 @@
state=present
encoding=utf8
- name: edxlocal | add the mongodb signing key
apt_key: >
id=7F0CEB10
url=http://docs.mongodb.org/10gen-gpg-key.asc
state=present
- name: edxlocal | add the mongodb repo to the sources list
apt_repository: >
repo='deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen'
state=present
- name: edxlocal | install mongo server and recommends
apt: pkg=mongodb-server state=present install_recommends=yes
apt: >
pkg=mongodb-10gen
state=present
install_recommends=yes
update_cache=yes
- name: edxlocal | stop mongo service
service: name=mongodb state=stopped
- name: edxlocal | move mongodb to /mnt
command: mv /var/lib/mongodb /mnt/. creates=/mnt/mongodb
- name: edxlocal | move mongodb to {{ storage_base_dir }}
command: mv /var/lib/mongodb {{ storage_base_dir }}/. creates={{ storage_base_dir }}/mongodb
- name: edxlocal | create mongodb symlink
file: src=/mnt/mongodb dest=/var/lib/mongodb state=link
file: src={{ storage_base_dir }}/mongodb dest=/var/lib/mongodb state=link
- name: edxlocal | start mongo service
service: name=mongodb state=started
......
---
# gh_users
#
# Creates OS accounts for users based on their github credential.
# Takes a list gh_users as a parameter which is a list of users
#
# roles:
# - role: gh_users
# gh_users:
# - user: github_admin_username
# groups:
# - adm
# - user: another_github_username
# groups: !!null
- fail: gh_users list must be defined for this parameterized role
when: not gh_users
- name: gh_users | create local user for github user
user:
name={{ item.user }}
groups={{ ",".join(item.groups) }}
shell=/bin/bash
with_items: gh_users
- name: gh_users | create .ssh directory
file:
path=/home/{{ item.user }}/.ssh state=directory mode=0700
owner={{ item.user }} group={{ item.user }}
with_items: gh_users
- name: gh_users | copy github key[s] to .ssh/authorized_keys
get_url:
url=https://github.com/{{ item.user }}.keys
dest=/home/{{ item.user }}/.ssh/authorized_keys mode=0600
owner={{ item.user }} group={{ item.user }}
with_items: gh_users
jenkins_home: /mnt/jenkins
jenkins_home: "{{ storage_base_dir }}/jenkins"
jenkins_user: "jenkins"
jenkins_group: "edx"
jenkins_server_name: "jenkins.testeng.edx.org"
......
......@@ -34,7 +34,7 @@
file: path={{ jenkins_home }} recurse=yes state=directory
owner={{ jenkins_user }} group={{ jenkins_group }}
# Symlink /var/lib/jenkins to /mnt/jenkins
# Symlink /var/lib/jenkins to {{ storage_base_dir }}/jenkins
# since Jenkins will expect its files to be in /var/lib/jenkins
- name: jenkins_master | Symlink /var/lib/jenkins
file: src={{ jenkins_home }} dest=/var/lib/jenkins state=link
......
---
jenkins_workspace: /mnt/jenkins
jenkins_workspace: "{{ storage_base_dir }}/jenkins"
jenkins_phantomjs_url: https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
jenkins_phantomjs_archive: phantomjs-1.9.1-linux-x86_64.tar.bz2
jenkins_phantomjs_folder: phantomjs-1.9.1-linux-x86_64
......@@ -48,10 +48,10 @@ jscover_url: "http://superb-dca2.dl.sourceforge.net/project/jscover/JSCover-1.0.
jscover_version: "1.0.2"
# Mongo config
mongo_dir: "/mnt/mongodb"
mongo_log_dir: "/mnt/logs/mongodb"
mongo_dir: "{{ storage_base_dir }}/mongodb"
mongo_log_dir: "{{ storage_base_dir }}/logs/mongodb"
# URL of S3 bucket containing pre-compiled Python packages
python_pkg_url: "https://s3.amazonaws.com/jenkins.python_pkgs"
python_download_dir: "/mnt/python_pkgs"
python_virtualenv: "/mnt/venv"
python_download_dir: "{{ storage_base_dir }}/python_pkgs"
python_virtualenv: "{{ storage_base_dir}}/venv"
---
# Configure Mongo to use /mnt so we don't
# Configure Mongo to use {{ storage_base_dir }} so we don't
# run out of disk space
- name: jenkins_worker | Stop mongo service
service: name=mongodb state=stopped
......
# Launches an ec2 instance and blocks until the instance is up
# adds it to the host group
- name: launch_ec2 | Launch ec2 instance
local_action:
module: ec2
keypair: "{{ keypair }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ ami }}"
wait: true
region: "{{ region }}"
instance_tags: "{{instance_tags}}"
root_ebs_size: "{{ root_ebs_size }}"
register: ec2
- name: launch_ec2 | Add DNS name
local_action:
module: route53
overwrite: yes
command: create
zone: "{{ dns_zone }}"
type: CNAME
ttl: 300
record: "{{ dns_name }}.{{ dns_zone }}"
value: "{{ item.public_dns_name }}"
with_items: "{{ ec2.instances }}"
- name: launch_ec2 | Add DNS name studio
local_action:
module: route53
overwrite: yes
command: create
zone: "{{ dns_zone }}"
type: CNAME
ttl: 300
record: "studio.{{ dns_name }}.{{ dns_zone }}"
value: "{{ item.public_dns_name }}"
with_items: "{{ ec2.instances }}"
- name: launch_ec2 | Add DNS name preview
local_action:
module: route53
overwrite: yes
command: create
zone: "{{ dns_zone }}"
type: CNAME
ttl: 300
record: "preview.{{ dns_name }}.{{ dns_zone }}"
value: "{{ item.public_dns_name }}"
with_items: "{{ ec2.instances }}"
- name: launch_ec2 | Add new instance to host group
local_action: >
add_host
hostname={{ item.public_ip }}
groupname=launched
with_items: "{{ ec2.instances }}"
- name: launch_ec2 | Wait for SSH to come up
local_action: >
wait_for
host={{ item.public_dns_name }}
state=started
port=22
delay=60
timeout=320
with_items: "{{ ec2.instances }}"
---
instance_tags: '{"from_ansible": "true"}'
# Launches an ec2 instance and blocks until the instance is up
# adds it to the host group
- name: launch_instance | Launch instance
local_action:
module: ec2
keypair: "{{keypair}}"
group: "{{security_group}}"
instance_type: "{{instance_type}}"
image: "{{image}}"
wait: true
region: "{{region}}"
instance_tags: "{{instance_tags}}"
register: ec2
- name: launch_instance | Add new instance to host group
local_action: add_host hostname=${item.public_ip} groupname=launched
with_items: ${ec2.instances}
- name: launch_instance | Wait for SSH to come up
local_action: wait_for host=${item.public_dns_name} port=22 delay=60 timeout=320 state=started
with_items: ${ec2.instances}
......@@ -12,12 +12,12 @@
service: name=mongodb state=stopped
tags: mongo
- name: mongo | move mongodb to /mnt
command: mv /var/lib/mongodb /mnt/. creates=/mnt/mongodb
- name: mongo | move mongodb to {{ storage_base_dir }}
command: mv /var/lib/mongodb {{ storage_base_dir}}/. creates={{ storage_base_dir }}/mongodb
tags: mongo
- name: mongo | create mongodb symlink
file: src=/mnt/mongodb dest=/var/lib/mongodb state=link
file: src={{ storage_base_dir }}/mongodb dest=/var/lib/mongodb state=link
tags: mongo
- name: mongo | copy configuration template
......
......@@ -38,7 +38,7 @@ NOTIFIER_USER_SERVICE_HTTP_AUTH_USER: "guido"
NOTIFIER_USER_SERVICE_HTTP_AUTH_PASS: "vanrossum"
NOTIFIER_CELERY_BROKER_URL: "django://"
NOTIFIER_SUPERVISOR_LOG_DEST: "/mnt/logs/supervisor"
NOTIFIER_SUPERVISOR_LOG_DEST: "{{ storage_base_dir }}/logs/supervisor"
NOTIFER_REQUESTS_CA_BUNDLE: "/etc/ssl/certs/ca-certificates.crt"
......
......@@ -23,7 +23,7 @@
# Assuming the following config
#
# my_role_s3fs_mounts:
# - { bucket: "my_bucket", mount_point: "/mnt/s3/my_bucket", owner: "root", group: "adm", mode: "0755" }
# - { bucket: "my_bucket", mount_point: "{{ storage_base_dir}}/s3/my_bucket", owner: "root", group: "adm", mode: "0755" }
#
# The role would need to include tasks like the following
#
......
......@@ -45,7 +45,7 @@ xqueue_env_config:
XQUEUE_WORKERS_PER_QUEUE: 12
LOGGING_ENV : $XQUEUE_LOGGING_ENV
SYSLOG_SERVER: $XQUEUE_SYSLOG_SERVER
LOG_DIR : '/mnt/logs/xqueue'
LOG_DIR : "{{ storage_base_dir }}/logs/xqueue"
RABBIT_HOST : $XQUEUE_RABBIT_HOSTNAME
S3_BUCKET : $XQUEUE_S3_BUCKET
S3_PATH_PREFIX: $XQUEUE_S3_PATH_PREFIX
......@@ -76,75 +76,22 @@ xqueue_post_requirements_file: "{{ xqueue_code_dir }}/requirements.txt"
# copied from the LMS role for now since there is a lot
# of overlap
xqueue_debian_pkgs:
- apparmor-utils
- aspell
# for compiling the virtualenv
# (only needed if wheel files aren't available)
- build-essential
- curl
- dvipng
- fabric
- g++
- gcc
- gfortran
- ghostscript
- git
- github-cli
- graphviz
- s3cmd
- pkg-config
- graphviz-dev
- gunicorn
- inoticoming
- ipython
- libcrypt-ssleay-perl
- libcurl4-openssl-dev
- libdigest-sha-perl
- libfreetype6-dev
- libgeos-dev
- libgraphviz-dev
- libjpeg8-dev
- liblapack-dev
- liblwp-protocol-https-perl
- graphviz
- libmysqlclient-dev
- libnet-amazon-ec2-perl
- libpng12-dev
- libreadline-dev
- libreadline6-dev
- libssl-dev
- libswitch-perl
- libwww-perl
- libxml++2.6-dev
- libxml2-dev
- libxml2-utils
- libxslt1-dev
- maven2
- mongodb-clients
- mysql-client
# apparmor
- apparmor-utils
# misc
- curl
- ipython
- npm
- ntp
- openjdk-7-jdk
- openjdk-7-jre
- pep8
- perl
- pkg-config
- postfix
- pylint
- python-boto
- python-coverage-test-runner
- python-django-nose
- python-jenkins
- python-nose
- python-nosexcover
- python-numpy
- python-pip
- python-scipy
- python-mysqldb
- rake
- reprepro
- rsyslog
- rubygems
- sqlite3
- super
- vagrant
- yui-compressor
- zip
- zlib1g-dev
# for shapely
- libgeos-dev
# Needed to be able to create the xqueue mysqldb.
- python-mysqldb
......@@ -5,12 +5,17 @@ RABBIT_RUN_URL: ''
RABBIT_GRADER_ROOT: ''
RABBIT_LOGGING_ENV: 'sandbox'
RABBIT_SYSLOG_SERVER: ''
# by default do not check out the content
# repo needed on the xserver for grading
# python submissions, TODO: replace with an open
# source repo
XSERVER_GRADER_CHECKOUT: False
xserver_env_config:
RUN_URL: $RABBIT_RUN_URL
GRADER_ROOT: $RABBIT_GRADER_ROOT
LOGGING_ENV: $RABBIT_LOGGING_ENV
LOG_DIR: '/mnt/logs/xserver'
LOG_DIR: "{{ storage_base_dir }}/logs/xserver"
SYSLOG_SERVER: $RABBIT_SYSLOG_SERVER
SANDBOX_PYTHON: '/opt/edx_apparmor_sandbox/bin/python'
......
......@@ -32,7 +32,7 @@
git: dest={{xserver_grader_dir}} repo={{xserver_grader_source}} version={{xserver_grader_version}}
environment:
GIT_SSH: /tmp/git_ssh.sh
when: c_skip_grader_checkout is not defined or c_skip_grader_checkout==False
when: XSERVER_GRADER_CHECKOUT
tags:
- deploy
......
#!/usr/bin/env bash
# Ansible configuration/deploy wrapper script that
# assumes the following parameters set
# as environment variables
#
# - dns_name - REQUIRED
# - dns_zone
# - edxapp_version
# - forum_version
# - xqueue_version
# - xserver_version
# - ora_version
# - ease_version
# - deploy
# - keypair
export BOTO_CONFIG=/var/lib/jenkins/${aws_account}.boto
if [[ -z $dns_name ]]; then
echo "The hostname is required to know what machine to configure"
exit 1
fi
if [[ ! -f $BOTO_CONFIG ]]; then
echo "AWS credentials not found for $aws_account"
exit 1
fi
extra_vars="/var/tmp/extra-vars-$$.yml"
cat << EOF > $extra_vars
---
EDXAPP_PREVIEW_LMS_BASE: preview.${dns_name}.${dns_zone}
EDXAPP_LMS_BASE: ${dns_name}.${dns_zone}
EDXAPP_LMS_PREVIEW_NGINX_PORT: 80
EDXAPP_CMS_NGINX_PORT: 80
XSERVER_GRADER_CHECKOUT: False
c_skip_grader_checkout: True
edx_platform_commit: $edxapp_version
forum_version: $forum_version
xqueue_version: $xqueue_version
xserver_version: $xserver_version
ora_version: $ora_version
ease_version: $ease_version
ansible_ssh_private_key_file: /var/lib/jenkins/${keypair}.pem
EOF
cat $extra_vars
cd playbooks/edx-east
./ec2.py --refresh
ansible-playbook -vvv $playbook -i ./ec2.py -e "@$extra_vars" --user ubuntu --tags deploy
#!/usr/bin/env bash
# Ansible provisioning wrapper script that
# assumes the following parameters set
# as environment variables
#
# - github_username
# - server_type
# - instance_type
# - region
# - aws_account
# - keypair
# - ami
# - root_ebs_size
# - security_group
# - dns_zone
# - dns_name
# - environment
# - name_tag
export BOTO_CONFIG=/var/lib/jenkins/${aws_account}.boto
function ascii_convert {
echo $1 | iconv -f utf8 -t ascii//TRANSLIT//IGNORE
}
# remove non-ascii chars from build user vars
BUILD_USER_LAST_NAME=$(ascii_convert $BUILD_USER_LAST_NAME)
BUILD_USER_FIRST_NAME=$(ascii_convert $BUILD_USER_FIRST_NAME)
BUILD_USER_ID=$(ascii_convert $BUILD_USER_ID)
BUILD_USER=$(ascii_convert $BUILD_USER)
if [[ -z $github_username ]]; then
github_username=$BUILD_USER_ID
fi
if [[ ! -f $BOTO_CONFIG ]]; then
echo "AWS credentials not found for $aws_account"
exit 1
fi
extra_vars="/var/tmp/extra-vars-$$.yml"
if [[ -z $dns_name ]]; then
dns_name=$github_username
fi
if [[ -z $name_tag ]]; then
name_tag=${github_username}-${environment}
fi
if [[ -z $ami ]]; then
if [[ $server_type == "full_edx_installation" ]]; then
ami="ami-c97727a0"
elif [[ $server_type == "ubuntu_12.04" ]]; then
ami="ami-d0f89fb9"
fi
fi
if [[ -z $instance_type ]]; then
if [[ $server_type == "full_edx_installation" ]]; then
instance_type="m1.medium"
elif [[ $server_type == "ubuntu_12.04" ]]; then
instance_type="m1.small"
fi
fi
cat << EOF > $extra_vars
---
EDXAPP_PREVIEW_LMS_BASE: preview.${dns_name}.${dns_zone}
EDXAPP_LMS_BASE: ${dns_name}.${dns_zone}
EDXAPP_LMS_PREVIEW_NGINX_PORT: 80
EDXAPP_CMS_NGINX_PORT: 80
ansible_ssh_private_key_file: /var/lib/jenkins/${keypair}.pem
dns_name: $dns_name
keypair: $keypair
instance_type: $instance_type
security_group: $security_group
ami: $ami
region: $region
instance_tags: '{"environment": "$environment", "github_username": "$github_username", "Name": "$name_tag", "source": "jenkins", "owner": "$BUILD_USER"}'
root_ebs_size: $root_ebs_size
gh_users:
- user: jarv
groups:
- adm
- user: feanil
groups:
- adm
- user: e0d
groups:
- adm
- user: ${github_username}
groups:
- adm
dns_zone: $dns_zone
EOF
cat $extra_vars
cd playbooks/edx-east
# run the tasks to launch an ec2 instance from AMI
ansible-playbook -vvvv edx_provision.yml -i inventory.ini -e "@${extra_vars}" --user ubuntu
# run tasks to update application config files for the sandbox hostname
if [[ $server_type == "full_edx_installation" ]]; then
ansible-playbook -vvvv edx_continuous_integration.yml -i "${dns_name}.${dns_zone}," -e "@${extra_vars}" --user ubuntu --tags "lms-env,cms-env,lms-preview-env"
fi
rm -f "$extra_vars"
......@@ -18,7 +18,7 @@ Vagrant.configure("2") do |config|
# point Vagrant at the location of your playbook you want to run
ansible.playbook = "../../playbooks/vagrant-fullstack.yml"
ansible.inventory_path = "../../playbooks/vagrant/inventory.ini"
ansible.extra_vars = { c_skip_grader_checkout: 'True' }
ansible.extra_vars = { XSERVER_GRADER_CHECKOUT: 'False' }
ansible.verbose = "extra"
end
end
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