Skip to content

Instantly share code, notes, and snippets.

@ankitsinghaniyaz
Created May 21, 2020 19:13
Show Gist options
  • Save ankitsinghaniyaz/a1a1185b3027327502a3d70f6b32271e to your computer and use it in GitHub Desktop.
Save ankitsinghaniyaz/a1a1185b3027327502a3d70f6b32271e to your computer and use it in GitHub Desktop.
Ansible file to setup a web develoipment environment in an Ubuntu(ish) OS
# Set up a development environment on an Ubuntu flavored linux distribution
# install and sets up:
# rbenv, nvm, mysql, postgres, redis
# vscode, slack, docker, chormium, tilix, heroku, postman, beekeeper, skype, kazam, peek and more
# setup an rsa key
# Usage:
# install ansible 2.7+ - latest
## sudo apt-add-repository ppa:ansible/ansible && sudo apt update && sudo apt install ansible
# run the playbook:
## ansible-playbook webdev.yaml -K -e "email=<[email protected]>"
---
- hosts: localhost
tasks:
- name: ensure dependencies are installed
become: true
apt:
state: latest
name:
- git
- python3-pip
- name: install nvm
git:
repo: 'https://github.com/creationix/nvm.git'
dest: '{{ ansible_env.HOME }}/.nvm'
update: no
- name: add nvm to path
lineinfile:
dest: '{{ ansible_env.HOME }}/.bashrc'
line: '{{ item.line }}'
with_items:
- { line: 'export NVM_DIR="$HOME/.nvm"' }
- { line: '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' }
- { line: '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' }
- name: install rbenv
git:
repo: 'https://github.com/rbenv/rbenv.git'
dest: '{{ ansible_env.HOME }}/.rbenv'
update: no
- name: add rbenv to path
lineinfile:
dest: '{{ ansible_env.HOME }}/.bashrc'
line: '{{ item.line }}'
with_items:
- { line: 'export PATH="$HOME/.rbenv/bin:$PATH"' }
- { line: 'eval "$(rbenv init -)"' }
- name: setup ruby builds
git:
repo: 'https://github.com/rbenv/ruby-build.git'
dest: '{{ ansible_env.HOME }}/.rbenv/plugins/ruby-build'
update: yes
- name: install redis
become: true
apt:
name: redis-server
state: present
- name: install mysql dependencies
become: yes
pip:
name: pymysql
state: present
- name: install mysql
become: true
apt:
pkg:
- mysql-server
- build-essential
- libmysqlclient-dev
- name: configure mysql
become: yes
mysql_user:
name: '{{ ansible_env.USER }}'
login_unix_socket: /var/run/mysqld/mysqld.sock
priv: '*.*:ALL,GRANT'
state: present
check_implicit_admin: yes
- name: install postgresql dependencies
become: yes
pip:
name: psycopg2
state: present
- name: install postgresql
become: true
apt:
pkg:
- postgresql
- postgresql-contrib
- libpq-dev
- name: configure postgres
become: true
become_user: postgres
postgresql_user:
name: '{{ ansible_env.USER }}'
role_attr_flags: CREATEDB,NOSUPERUSER
- name: create default postgres data for user
postgresql_db:
name: '{{ ansible_env.USER }}'
owner: '{{ ansible_env.USER }}'
login_user: '{{ ansible_env.USER }}'
- name: generate ssh rsa host key
command : 'ssh-keygen -q -t rsa -f {{ ansible_env.HOME }}/.ssh/id_rsa -C "{{ email }}" -N ""'
args:
creates: '{{ ansible_env.HOME }}/.ssh/id_rsa'
- name: install docker and compose
become: true
apt:
pkg:
- docker
- docker-compose
# Install some most frequenty needed tools
- name: install apt packages
become: true
apt:
pkg:
- tilix
- redshift
- kazam
- vim
- peek
- xclip
- name: install snap classic packages
become: true
snap:
classic: yes
name:
- slack
- code
- heroku
- skype
- name: install snap packages
become: true
snap:
name:
- zoom-client
- chromium
- beekeeper-studio
- postman
- spotify
- name: configure aliases
lineinfile:
dest: '{{ ansible_env.HOME }}/.bash_aliases'
line: '{{ item.line }}'
create: yes
with_items:
- { line: 'alias ga="git add"' }
- { line: 'alias gaa="git add ."' }
- { line: 'alias gaaa="git add -A"' }
- { line: 'alias gb="git branch"' }
- { line: 'alias gbd="git branch -d "' }
- { line: 'alias gc="git commit"' }
- { line: 'alias gcm="git commit -m"' }
- { line: 'alias gco="git checkout"' }
- { line: 'alias gcob="git checkout -b"' }
- { line: 'alias gcom="git checkout master"' }
- { line: 'alias gd="git diff"' }
- { line: 'alias gda="git diff HEAD"' }
- { line: 'alias gi="git init"' }
- { line: 'alias gl="git log"' }
- { line: 'alias glg="git log --graph --oneline --decorate --all"' }
- { line: 'alias gld="git log --pretty=format:%h %ad %s --date=short --all"' }
- { line: 'alias gm="git merge --no-ff"' }
- { line: 'alias gp="git pull"' }
- { line: 'alias gss="git status -s"' }
- { line: 'alias gst="git stash"' }
- { line: 'alias gstl="git stash list"' }
- { line: 'alias gstp="git stash pop"' }
- { line: 'alias gstd="git stash drop"' }
- { line: 'alias gpsh="git push"' }
- { line: 'alias alias-edit="vim ~/.bash_aliases"' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment