From dcb40e00c5cd63a423d15088c175ad0d8e844a4b Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 9 May 2017 20:25:07 -0400 Subject: [PATCH] Set up directory structure and a common role as well as a developer-machine role --- group_vars/all | 4 + hosts | 2 + playbooks/developer-machine.yml | 14 +++ roles/common/tasks/main.yml | 119 +++++++++++++++++++++++++ roles/developer-machine/tasks/main.yml | 25 ++++++ site.yml | 9 ++ 6 files changed, 173 insertions(+) create mode 100644 group_vars/all create mode 100644 hosts create mode 100644 playbooks/developer-machine.yml create mode 100644 roles/common/tasks/main.yml create mode 100644 roles/developer-machine/tasks/main.yml create mode 100644 site.yml diff --git a/group_vars/all b/group_vars/all new file mode 100644 index 0000000..aeb4c83 --- /dev/null +++ b/group_vars/all @@ -0,0 +1,4 @@ +--- +# Variables listed here are applicable to all host groups + +example_password: somethingSecret diff --git a/hosts b/hosts new file mode 100644 index 0000000..b16ef94 --- /dev/null +++ b/hosts @@ -0,0 +1,2 @@ +[developer-machines] +codydev diff --git a/playbooks/developer-machine.yml b/playbooks/developer-machine.yml new file mode 100644 index 0000000..f8887e3 --- /dev/null +++ b/playbooks/developer-machine.yml @@ -0,0 +1,14 @@ +--- +# This playbook deploys a development machine + +- name: Apply common configuration to all nodes + hosts: developer-machines + user: root + tasks: + - include: ../roles/common/tasks/main.yml + +- name: Apply common configuration to all nodes + hosts: developer-machines + user: root + tasks: + - include: ../roles/developer-machine/tasks/main.yml diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml new file mode 100644 index 0000000..00b158c --- /dev/null +++ b/roles/common/tasks/main.yml @@ -0,0 +1,119 @@ +--- +# This playbook contains plays that will run on all nodes + +- name: Update apt + apt: update_cache=yes + +- name: Upgrade APT to the lastest packages + apt: upgrade=safe + +- name: Install htop + apt: name=htop state=present + +- name: Install curl + apt: name=curl state=present + +- name: Install openssh-server + apt: name=openssh-server state=present + +- name: Install git + apt: name=git state=present + +- name: Install rsync + apt: name=rsync state=present + +- name: Install zip + apt: name=zip state=present + +- name: Install unzip + apt: name=unzip state=present + +- name: Install fail2ban + apt: name=fail2ban state=present + +- name: Install ntp + apt: name=ntp state=present + +- name: Install mysql-client + apt: name=mysql-client state=present + +- name: Install wget + apt: name=wget state=present + +- name: Set git username + shell: git config --global user.name "Jacob Cody Wimer" + +- name: Set git email + shell: git config --global user.email "jacob.wimer@gmail.com" + +- name: Is docker installed + shell: which docker + register: docker_installed + +- name: Get docker + shell: curl -sSL https://get.docker.com/ | sh + when: docker_install is none + +- name: Get docker compose + shell: curl -L https://github.com/docker/compose/releases/download/1.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose + when: docker_install is none + +- name: Link docker compose + shell: chmod +x /usr/local/bin/docker-compose + when: docker_install is none + +- name: Set timezone to NewYork + shell: timedatectl set-timezone America/New_York + +- name: test for swap partition + shell: swapon -s | grep -E "^/" + register: swapfile + ignore_errors: yes + +- name: create swapfile + when: swapfile|failed + shell: fallocate -l 4G /swapfile + +- name: set swapfile permissions + when: swapfile|failed + file: path=/swapfile + owner=root + group=root + mode=0600 + +- name: prepare swapfile + when: swapfile|failed + shell: mkswap /swapfile + +- name: enable swap + when: swapfile|failed + shell: swapon /swapfile + +- name: add swapfile + when: swapfile|failed + lineinfile: dest=/etc/fstab + regexp="^/swapfile" + state=present + line="/swapfile none swap sw 0 0" + +- name: set swappiness (temporarily) + when: swapfile|failed + shell: echo 10 | tee /proc/sys/vm/swappiness + +- name: set swappiness (permanent) + when: swapfile|failed + lineinfile: dest=/etc/sysctl.conf + regexp="^vm.swappiness" + state=present + line="vm.swappiness = 10" + +- name: set cache pressure (temporarily) + when: swapfile|failed + shell: echo 50 | tee /proc/sys/vm/vfs_cache_pressure + +- name: set cache pressure (permanent) + when: swapfile|failed + lineinfile: dest=/etc/sysctl.conf + regexp="^vm.vfs_cache_pressure" + state=present + line="vm.swappiness = 50" diff --git a/roles/developer-machine/tasks/main.yml b/roles/developer-machine/tasks/main.yml new file mode 100644 index 0000000..a1d83af --- /dev/null +++ b/roles/developer-machine/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# This playbook contains plays that will run on developer-machines + +- name: Is rvm installed + shell: which rvm + register: rvm_installed + +- name: Install rvm key + shell: gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 + when: rvm_installed is none + +- name: Install rvm and latest ruby + shell: \curl -sSL https://get.rvm.io | bash -s stable + when: rvm_installed is none + +- name: Is heroku installed + shell: which heroku + register: heroku_installed + +- name: Install heroku toolbelt + shell: wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh + when: heroku_installed is none + +- name: Install siege + apt: name=siege state=present diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..93f9528 --- /dev/null +++ b/site.yml @@ -0,0 +1,9 @@ +--- +# This playbook deploys the whole application stack for my homelab +# +- name: Gather facts for all + hosts: all + remote_user: root + gather_facts: true + +- include: playbooks/developer-machine.yml