Last active
December 29, 2018 12:45
-
-
Save abby-fuller/2d7402c0f3269bed68aa19d5aaf02598 to your computer and use it in GitHub Desktop.
sample ansible provision.yml
This file contains 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
--- | |
#ansible provisioner for vagrant. this will run initially at 'vagrant up', | |
#and can be rerun with 'vagrant provision' | |
- hosts: all | |
gather_facts: no | |
vars_files: | |
- ../conf/secrets.yml | |
tasks: | |
#add mongo to apt | |
#add docker to apt | |
#update apt packages | |
#install host apt requirements | |
- name: install host requirements | |
apt: name={{ item }} state=present | |
sudo: yes | |
with_items: | |
- build-essential | |
- git | |
- python | |
- python-setuptools | |
- mongodb-org-shell | |
- docker-engine=1.9.1-0~trusty | |
#install pip for ansible requirements | |
- name: install pip | |
sudo: yes | |
command: easy_install -U pip | |
- name: install docker-py | |
sudo: yes | |
pip: name=docker-py state=present version=1.1.0 | |
- name: install awscli | |
sudo: yes | |
pip: name=awscli state=latest | |
#configure awscli | |
#docker setup | |
- name: login for config | |
sudo: yes | |
shell: export AWS_CONFIG_FILE=/home/vagrant/.aws/config; ECR_LOGIN="$(aws ecr get-login --region us-east-1)"; $ECR_LOGIN; | |
- name: login to ecr | |
sudo: yes | |
shell: export AWS_CONFIG_FILE=/home/vagrant/.aws/config; ECR_LOGIN="$(aws ecr get-login --region us-east-1)"; echo $ECR_LOGIN | awk '{print $6}'; | |
register: docker_pass | |
- set_fact: | |
DOCKER_PASS: "{{ docker_pass.stdout }}" | |
- name: give vagrant user access to docker | |
command: usermod -aG docker vagrant | |
sudo: true | |
- name: copy ecr login | |
sudo: yes | |
shell: cp -Rf /root/.docker/ /home/vagrant/.docker/ | |
- name: clone all the things | |
git: repo=git@github.com:airtimemedia/{{ item }}.git | |
dest=/vagrant/services/{{ item }} | |
track_submodules=yes | |
update=yes | |
accept_hostkey=yes | |
version=develop | |
ignore_errors: yes | |
with_items: | |
- deathstar | |
- stormtrooper | |
#start redis and mongodb containers | |
- name: run redis container | |
sudo: yes | |
docker: | |
name: redis | |
image: redis | |
command: redis-server --appendonly yes | |
state: reloaded | |
ports: | |
- '6379:6379' | |
expose: | |
- 6379 | |
- name: run mongodb container | |
sudo: yes | |
docker: | |
name: mongo | |
image: mongo | |
state: reloaded | |
ports: | |
- '27017:27017' | |
expose: | |
- 27017 | |
#pull and run docker containers for each service | |
#start deathstar | |
- name: pull/start deathstar container | |
sudo: yes | |
docker: | |
name: deathstar | |
image: "{{ AWS_DOCKER_REGISTRY }}/deathstar_test:develop" | |
username: AWS | |
password: "{{ DOCKER_PASS }}" | |
registry: "{{ AWS_DOCKER_REGISTRY }}" | |
state: reloaded | |
pull: always | |
insecure_registry: yes | |
detach: yes | |
links: | |
- "redis:redis" | |
- "mongo:mongo" | |
ports: | |
- "<port>:80" | |
volumes: | |
- "/vagrant/services/deathstar:/srv:rw" | |
env: | |
CLUSTER_SIZE: 2 | |
REDIS_HOST: redis | |
REDIS_PORT: 6379 | |
MONGODB_URL: mongodb://mongo:27017/deathstar | |
- name: npm install for deathstar | |
sudo: yes | |
shell: docker exec -it deathstar sh -c "rm -rf node_modules && npm install --color false --progress false" | |
ignore_errors: yes | |
- name: restart deathstar | |
sudo: yes | |
shell: docker exec deathstar supervisorctl restart deathstar | |
- name: wait for deathstar | |
wait_for: host=localhost port=<port> | |
#install npm modules for empire | |
- name: install node modules for empire | |
sudo: no | |
npm: path=/vagrant | |
ignore_scripts=yes | |
state=present | |
ignore_errors: yes | |
# Deal with any cross container linking required | |
- name: Get Deathstar IP | |
shell: echo $(sudo docker inspect --format \{\{' .NetworkSettings.IPAddress '\}\} deathstar) | |
register: DEATHSTAR_IP | |
ignore_errors: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment