Skip to content

Instantly share code, notes, and snippets.

@allomov
Last active August 29, 2015 14:20
Show Gist options
  • Save allomov/59e77b8aa19c2ee8fddd to your computer and use it in GitHub Desktop.
Save allomov/59e77b8aa19c2ee8fddd to your computer and use it in GitHub Desktop.
Template for making jumpbox ansible playbook for different cases

Description

This gist is a template for making jumpbox ansible playbook for different cases This playbook is used for Ubuntu servers with ansible 1.9

How to use

Run with a simple command:

ansible-playbook jumpbox-playbook.yml -i hosts
[jumpbox]
x.x.x.x ansible_ssh_private_key_file=./ssh/id_rsa ansible_ssh_user=cloud ansible_sudo=true
---
- hosts: jumpbox
vars:
go_version: 1.4.2
ruby_version: 2.1.5
username: cloud
standard_path: "{{ ansible_env.PATH }}"
gopath: "/home/{{username}}/go"
goroot: "/opt/go"
go_environment:
GOROOT: "{{goroot}}"
GOPATH: "{{gopath}}"
PATH: "{{goroot}}/bin:{{gopath}}/bin:{{gopath}}/src/github.com/cloudfoundry/bosh-init/out:{{standard_path}}"
remote_user: cloud
tasks:
- name: Run apt-get update
shell: for i in 1 2 3; do apt-get update -yq --fix-missing ; done;
sudo: true
- name: Install packages
sudo: true
apt: name={{item}}
with_items: [
git, mercurial, libssl-dev, lsof, strace, tcpdump,
zip, unzip, libcurl3, libcurl3-dev, libreadline6-dev,
bison, libxml2, libxml2-dev, libxslt1.1, libxslt1-dev,
libsqlite3-dev, rsync, libbz2-dev, cmake, uuid-dev,
libgcrypt-dev, ca-certificates, zlib1g, zlib1g-dev,
readline-common, curl, wget, libpq-dev, python-psycopg2,
bzr, autoconf, build-essential, libyaml-dev, libncurses5-dev,
libffi-dev, libgdbm3, libgdbm-dev, tmux, vim
]
- name: Creates ~/.ssh directory
file: "path=/home/{{username}}/.ssh state=directory"
- name: Download Ruby
shell: "wget http://ftp.ruby-lang.org/pub/ruby/ruby-{{ruby_version}}.tar.gz"
args: {chdir: /opt, creates: "/opt/ruby-{{ruby_version}}.tar.gz"}
- name: Untar Ruby
shell: "tar -xzvf ruby-{{ruby_version}}.tar.gz"
args: {chdir: /opt, creates: "/opt/ruby-{{ruby_version}}"}
- name: Remove RDoc directory # because of this issue https://groups.google.com/forum/#!topic/emm-ruby/hPcn7cMqwg4
file: "path=/opt/ruby-{{ruby_version}}/.ext/rdoc state=absent"
- name: Install Ruby
sudo: true
shell: "./configure && make && make install"
args: {chdir: "/opt/ruby-{{ruby_version}}", creates: "/usr/local/bin/ruby"}
- gem: name=bundler state=latest
- gem: name=bosh_cli version=1.2922.0
- gem: name=bosh_cli_plugin_micro version=1.2922.0
- gem: name=nats state=latest
- name: Download Go
sudo: true
shell: "wget https://storage.googleapis.com/golang/go{{go_version}}.linux-amd64.tar.gz"
args: {chdir: /opt, creates: "/opt/go{{go_version}}.linux-amd64.tar.gz"}
- name: Untar Go
sudo: true
shell: "tar xvf go{{go_version}}.linux-amd64.tar.gz"
args: {chdir: /opt, creates: "/opt/go"}
environment:
GOROOT: "/opt/go"
PATH: "$GOROOT/bin:$PATH"
- name: Creates GOPATH
file: "path=/home/{{username}}/go state=directory"
- file: src=/opt/go/bin/go dest=/usr/bin/go state=link
- name: See if environment are set
command: "grep GOROOT /etc/profile"
register: goroot_variable_from_env
ignore_errors: True
- name: Set environment variables
sudo: true
shell: "echo '{{item}}' >> /etc/profile"
with_items:
- "export GOROOT=/opt/go"
- "export GOPATH=/home/{{username}}/go"
- "export PATH=$GOROOT/bin:$GOPATH/bin:$GOPATH/src/github.com/cloudfoundry/bosh-init/out:$PATH"
when: (goroot_variable_from_env.stdout == "")
- name: Get bosh-init
shell: "go get -d github.com/cloudfoundry/bosh-init"
args: {creates: "{{gopath}}/src/github.com/cloudfoundry/bosh-init/"}
environment: go_environment
- name: Revert bosh-init # because of https://github.com/cloudfoundry/bosh-init/issues/21
shell: "git checkout 8c27d326388324349cb5ed18a1536cfa15215b1c"
args: {chdir: "{{gopath}}/src/github.com/cloudfoundry/bosh-init/"}
- name: Build bosh-init
shell: "./bin/build"
args:
chdir: "{{gopath}}/src/github.com/cloudfoundry/bosh-init/"
creates: "{{gopath}}/src/github.com/cloudfoundry/bosh-init/out/bosh-init"
environment: go_environment
- name: Install direnv
get_url: "url=https://github.com/zimbatm/direnv/releases/download/v2.6.0/direnv.linux-amd64 dest=/usr/local/bin/direnv"
- file: path=/usr/local/bin/direnv mode=755
- shell: echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
- name: Install CF CLI
get_url: "url=https://cli.run.pivotal.io/stable?release=linux64-binary&source=github dest=/usr/local/bin/cf"
- file: path=/usr/local/bin/cf mode=755
@ldmberman
Copy link

vars.username and remote_user values should probably be set to {{username}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment