Skip to content

Commit

Permalink
Migrate bootstrap to ansible playbooks (#184)
Browse files Browse the repository at this point in the history
Migrate bootstrap to ansible playbooks
  • Loading branch information
daniel-yavorovich authored and Orie Steele committed Jul 20, 2018
1 parent 577e406 commit 7bfed06
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 500 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ okta.pem
.env

attic

.idea/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ matrix:

before_script:
# bootstrap installs global dev dependencies, including the transmute-cli
- source ./bootstrap
- bash ./bootstrap
- source ~/.bashrc
# This setup overwrites the transmute-cli with a build from the current branch (so the cli is tested)
- cd $TRAVIS_BUILD_DIR/packages/transmute-cli
- npm i
Expand Down
13 changes: 13 additions & 0 deletions ansible-playbook/roles/certbot/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: install certbot
get_url:
url: "https://dl.eff.org/certbot-auto"
dest: "{{ transmute_bin }}/certbot-auto"
remote_src: yes
mode: 0755

- name: certbot-auto --noninteractive
shell: "certbot-auto --noninteractive"
args:
chdir: "{{ transmute_bin }}"
ignore_errors: yes
103 changes: 103 additions & 0 deletions ansible-playbook/roles/dependencies/tasks/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
- name: install packages
package:
name: "{{ item }}"
state: present
become: yes
with_items:
- libncurses5-dev
- libslang2-dev
- gettext
- zlib1g-dev
- libselinux1-dev
- debhelper
- lsb-release
- pkg-config
- po-debconf
- autoconf
- automake
- autopoint
- libtool
- bison
- curl
- git
- socat
- jq
- virtualbox

- name: create temporary directory NSENTER_TMP
tempfile:
state: directory
suffix: NSENTER_TMP
register: tmp

- name: Unarchive util-linux
unarchive:
src: "https://www.kernel.org/pub/linux/utils/util-linux/v2.30/util-linux-2.30.2.tar.gz"
dest: "{{ tmp.path }}"
remote_src: yes

- name: build nsenter
shell: "./autogen.sh && ./configure && make nsenter"
args:
chdir: "{{ tmp.path }}/util-linux-2.30.2"

- name: Create dir {{ transmute_bin }}
file:
path: "{{ ansible_env.HOME }}/.local/bin"
state: directory
recurse: yes

- name: Copy nsenter
copy:
src: "{{ tmp.path }}/util-linux-2.30.2/nsenter"
dest: "{{ ansible_env.HOME }}/.local/bin/nsenter"
remote_src: yes
mode: 0750

- name: Copy nsenter
copy:
src: "{{ tmp.path }}/util-linux-2.30.2/nsenter"
dest: "/usr/bin/nsenter"
remote_src: yes
mode: 0755
become: yes

- name: install kubectl
get_url:
url: "https://storage.googleapis.com/kubernetes-release/release/{{ transmute_kube_version }}/bin/linux/amd64/kubectl"
dest: "/usr/local/bin/kubectl"
remote_src: yes
mode: 0755
owner: 0
group: 0
become: yes

- name: install minikube
get_url:
url: "https://storage.googleapis.com/minikube/releases/v0.25.2/minikube-linux-amd64"
dest: "/usr/local/bin/minikube"
remote_src: yes
mode: 0755
owner: 0
group: 0
become: yes

- name: create temporary directory HELM_TMP
tempfile:
state: directory
suffix: HELM_TMP
register: tmp

- name: Unarchive helm
unarchive:
src: "https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz"
dest: "{{ tmp.path }}"
remote_src: yes

- name: Copy helm
copy:
src: "{{ tmp.path }}/linux-amd64/helm"
dest: "{{ ansible_env.HOME }}/.transmute/bin/helm"
remote_src: yes
mode: 0750
39 changes: 39 additions & 0 deletions ansible-playbook/roles/dependencies/tasks/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: install homebrews
homebrew:
name: "{{ item }}"
state: present
with_items:
- kubectl
- kubernetes-helm
- kubernetes-cli
- coreutils
- curl
- git
- socat
- jq

- name: link kubernetes-cli
homebrew:
name: "kubernetes-cli"
state: linked
ignore_errors: yes

- name: install gnupg
homebrew:
name: "gnupg"
state: present
ignore_errors: yes

- name: install minikube
homebrew_cask:
name: "minikube"
state: present


- name: install virtualbox
homebrew_cask:
name: "virtualbox"
state: present


8 changes: 8 additions & 0 deletions ansible-playbook/roles/dependencies/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

- include: linux.yml
when: "ansible_system == 'Linux' and ansible_machine == 'x86_64'"

- include: macos.yml
when: "ansible_system == 'Darwin' and ansible_machine == 'x86_64'"

27 changes: 27 additions & 0 deletions ansible-playbook/roles/dotfiles_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---

- name: touch {{ ansible_env.HOME }}/.zshrc
file:
path: "{{ ansible_env.HOME }}/.zshrc"
state: touch

- name: touch {{ ansible_env.HOME }}/.bashrc
file:
path: "{{ ansible_env.HOME }}/.bashrc"
state: touch

- name: set TRANSMUTE_BIN variable
set_fact: transmute_bin="{{ ansible_env.HOME }}/.transmute/bin"

- name: Create dir {{ transmute_bin }}
file:
path: "{{ transmute_bin }}"
state: directory

- name: add PATH to {{ ansible_env.HOME }}/.zshrc and {{ ansible_env.HOME }}/.bashrc
lineinfile:
path: "{{ item }}"
line: 'export PATH={{ transmute_bin }}:$PATH'
with_items:
- "{{ ansible_env.HOME }}/.zshrc"
- "{{ ansible_env.HOME }}/.bashrc"
4 changes: 4 additions & 0 deletions ansible-playbook/roles/nvm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- include: nvm_install.yml

- include: npm_packages.yml
9 changes: 9 additions & 0 deletions ansible-playbook/roles/nvm/tasks/npm_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Install npm packages globally
shell: 'bash -c "source {{ ansible_env.HOME }}/.nvm/nvm.sh && npm i -g {{ item }}"'
with_items:
- '--unsafe-perm ngrok'
- '[email protected]'
- '[email protected]'
- 'transmute-cli'
38 changes: 38 additions & 0 deletions ansible-playbook/roles/nvm/tasks/nvm_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

- name: check if nvm already installed
stat:
path: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
register: nvm_stat

- name: create temporary directory NVM_TMP
tempfile:
state: directory
suffix: NVM_TMP
register: tmp
when: nvm_stat.stat.isreg is not defined or not nvm_stat.stat.isreg

- name: Download nvm installer
get_url:
url: https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh
dest: "{{ tmp.path }}/install.sh"
mode: 0750
when: nvm_stat.stat.isreg is not defined or not nvm_stat.stat.isreg

- name: install nvm
shell: "{{ tmp.path }}/install.sh"
when: nvm_stat.stat.isreg is not defined or not nvm_stat.stat.isreg

- name: Source nvm in {{ ansible_env.HOME }}/.profile
lineinfile: dest="{{ ansible_env.HOME }}/{{ item }}" line="source ~/.nvm/nvm.sh" create=yes
with_items:
- .profile
- .bashrc

- name: Install node
shell: 'bash -c "source {{ ansible_env.HOME }}/.profile && nvm ls-remote --lts=carbon && nvm install --lts=carbon"'
register: nvm_install_result
changed_when: "'is already installed.' not in nvm_install_result.stdout"

- name: Set default node version to carbon
shell: 'bash -c "source {{ ansible_env.HOME }}/.profile && nvm alias default lts/carbon"'
9 changes: 9 additions & 0 deletions ansible-playbook/roles/transmute/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: generate {{ ansible_env.HOME }}/.transmute/.env
template:
src: ".env.j2"
dest: "{{ ansible_env.HOME }}/.transmute/.env"

- name: Install npm packages globally
shell: 'bash -c "source {{ ansible_env.HOME }}/.nvm/nvm.sh && npm i -g transmute-cli"'
become: no
7 changes: 7 additions & 0 deletions ansible-playbook/roles/transmute/templates/.env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

TRANSMUTE_VERBOSITY=10
TRANSMUTE_DIR={{ ansible_env.HOME }}/.transmute
TRANSMUTE_BIN={{ transmute_bin }}
TRANSMUTE_REPO={{ ansible_env.HOME }}/.transmute/git/transmute
TRANSMUTE_KUBE_VERSION={{ transmute_kube_version }}
16 changes: 16 additions & 0 deletions ansible-playbook/transmute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: transmute
vars:
fix_dotfiles: true
transmute_kube_version: "v1.9.4"
nvm_version: "v0.33.11"
hosts: localhost
connection: local
gather_facts: yes
roles:
- role: dotfiles_install
when: fix_dotfiles
- role: dependencies
- role: nvm
- role: certbot
- role: transmute
Loading

0 comments on commit 7bfed06

Please sign in to comment.