Last active
August 7, 2017 22:10
-
-
Save iambibhas/c9635d216b626f84cc44 to your computer and use it in GitHub Desktop.
Ansible playbook for KLP vagrant box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install virtualbox and vagrant http://www.vagrantup.com/downloads | |
sudo pip install ansible | |
vagrant plugin install vagrant-vbguest | |
git clone [email protected]:klpdotorg/dubdubdub.git ./ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: default | |
vars: | |
http_port: 80 | |
max_clients: 200 | |
locale: en_US.UTF-8 | |
timezone: Asia/Kolkata | |
venv_path: /home/vagrant/envs/dubdubdub | |
user: vagrant | |
sudo: True | |
tasks: | |
- name: ensure locale en_US.UTF-8 exists | |
locale_gen: name={{ locale }} state=present | |
- name: update locale | |
command: /usr/sbin/update-locale LANG={{ locale }} | |
- name: Set timezone variables | |
copy: content={{ timezone }}\n | |
dest=/etc/timezone | |
owner=root | |
group=root | |
mode=0644 | |
backup=yes | |
notify: | |
- update timezone | |
- name: update apt cache | |
command: "/usr/bin/aptitude update" | |
- name: "upgrade apt packages, about 200MB" | |
command: "/usr/bin/aptitude safe-upgrade -y" | |
- name: install wget and ca-certificate | |
apt: pkg={{ item }} state=latest | |
with_items: | |
- wget | |
- ca-certificates | |
- name: adding postgres repo | |
apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' state=present | |
- name: import postgresql repo key | |
apt_key: url=https://www.postgresql.org/media/keys/ACCC4CF8.asc state=present | |
- name: ensure postgresql 9.3 is installed | |
apt: pkg=postgresql-9.3 state=latest | |
- name: ensure postgresql is running | |
service: name=postgresql state=started | |
- name: install all required packages | |
apt: pkg={{ item }} state=latest | |
with_items: | |
- postgresql-contrib-9.3 | |
- postgresql-server-dev-9.3 | |
- postgresql-9.3-postgis-2.1 | |
- python-setuptools | |
- build-essential | |
- python2.7-dev | |
- libjpeg-dev | |
- python-pip | |
- python-psycopg2 | |
- name: install virtualenv | |
pip: name=virtualenv | |
- name: create database | |
sudo_user: postgres | |
postgresql_db: name=dubdubdub | |
encoding='UTF-8' | |
lc_collate='en_US.UTF-8' | |
lc_ctype='en_US.UTF-8' | |
template='template0' | |
- name: create postgresql user and give privileges | |
sudo_user: postgres | |
postgresql_user: db=dubdubdub name=klp password=klp priv=ALL | |
- name: create pgpass | |
sudo_user: postgres | |
copy: content=localhost:5432:*:klp:klp | |
dest=/var/lib/postgresql/.pgpass | |
owner=postgres | |
group=postgres | |
mode=0600 | |
- name: install dependencies into virtualenv | |
sudo: False | |
pip: requirements=/vagrant/requirements.txt virtualenv={{ venv_path }} state=present | |
- name: ensure virtualenv is active when user logs in | |
lineinfile: dest=/home/vagrant/.bashrc line='cd /vagrant && source {{ venv_path }}/bin/activate' state=present | |
- name: create alias for runserver | |
lineinfile: dest=/home/vagrant/.bashrc line='alias runserver="python manage.py runserver 0.0.0.0:8000"' state=present | |
handlers: | |
- name: update timezone | |
command: dpkg-reconfigure --frontend noninteractive tzdata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
# Every Vagrant virtual environment requires a box to build off of. | |
config.vm.box = "dub3" | |
config.vm.box_url = "http://files.vagrantup.com/precise64.box" | |
config.vm.network :forwarded_port, guest: 8000, host: 8088 | |
config.vm.network "public_network" | |
config.vm.provision "ansible" do |ansible| | |
ansible.verbose = 'v' | |
ansible.playbook = "playbook.yml" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment