4/28/2015 - 12:05 PM

Template for making jumpbox ansible playbook for different cases

Template for making jumpbox ansible playbook for different cases

- hosts: jumpbox
    go_version: 1.4.2
    ruby_version: 2.1.5
    username: cloud
    standard_path: "{{ ansible_env.PATH }}"
    gopath: "/home/{{username}}/go"
    goroot: "/opt/go"
      GOROOT: "{{goroot}}"
      GOPATH: "{{gopath}}"
      PATH: "{{goroot}}/bin:{{gopath}}/bin:{{gopath}}/src/{{standard_path}}"
  remote_user: cloud
  - 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{{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!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{{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"}
        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"
      - "export GOROOT=/opt/go"
      - "export GOPATH=/home/{{username}}/go"
      - "export PATH=$GOROOT/bin:$GOPATH/bin:$GOPATH/src/$PATH"
    when: (goroot_variable_from_env.stdout == "")

  - name: Get bosh-init
    shell: "go get -d"
    args: {creates: "{{gopath}}/src/"}
    environment: go_environment

  - name: Revert bosh-init # because of
    shell: "git checkout 8c27d326388324349cb5ed18a1536cfa15215b1c"
    args: {chdir: "{{gopath}}/src/"}
  - name: Build bosh-init 
    shell: "./bin/build"
      chdir: "{{gopath}}/src/"
      creates: "{{gopath}}/src/"
    environment: go_environment

  - name: Install direnv
    get_url: "url= 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= dest=/usr/local/bin/cf"
  - file: path=/usr/local/bin/cf mode=755
x.x.x.x ansible_ssh_private_key_file=./ssh/id_rsa ansible_ssh_user=cloud ansible_sudo=true


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