├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── ansible.cfg ├── group_vars └── appservers ├── inventory ├── kubernetes ├── README.md └── appservers │ └── rc.yml ├── provisioning ├── roles │ ├── app │ │ ├── meta │ │ │ └── main.yml │ │ ├── tasks │ │ │ └── main.yml │ │ └── vars │ │ │ └── main.yml │ └── java │ │ ├── files │ │ └── jre-8u45-linux-x64.rpm │ │ ├── tasks │ │ └── main.yml │ │ ├── templates │ │ └── java.sh.j2 │ │ └── vars │ │ └── main.yml └── site.yml └── vault.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Siili Solutions Poland 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of devoxx-ansible nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kansible demo for Spring Boot 2 | 3 | This is a simple example of provisioning an executable Spring Boot jar with Ansible. 4 | 5 | # Environment (machines) 6 | 7 | We use Ansible to install the Java App on application servers (```appservers``` group). 8 | 9 | # How to use it 10 | 11 | Required software: 12 | > 13 | * *Vagrant* (https://www.vagrantup.com/) **version 1.7.0 or later1** - requires any virtualization software (e.g. VirtualBox) 14 | * *Ansible* (http://ansible.com/) **version 1.9 or later** 15 | 16 | You can download latest version of Vagrant from its homepage. Ansible can be installed using system package manager or ```pip```. 17 | 18 | Required hardware: 19 | 20 | * Linux like operating system 21 | * at least 2GB of RAM (each machine from this sample uses at most 512MB of RAM). 22 | 23 | ## Start machines 24 | 25 | To test Ansible scripts you need to start vagrant machines. We provide ```Vagrantfile``` with suitable configuration. To start all machines invoke command: 26 | ```bash 27 | vagrant up 28 | ``` 29 | 30 | Starting machines for the first time might take few minutes, since Vagrant has to download CentOS image. 31 | 32 | ## Provision machines 33 | 34 | Provisioning is done by Ansible. On application servers Ansible scripts install and configure Oracle Java JRE and the App. 35 | Invoke this command to provision all machines: 36 | ```bash 37 | ansible-playbook -i inventory provisioning/site.yml -vv --ask-vault-pass 38 | ``` 39 | 40 | ### Ansible Vault 41 | 42 | During the provisioning you will be prompted for Ansible Vault password, type: ```vault```. It is used for decrypting ```vault.yml``` file which holds the credentials for HAProxy statistics page. You can view the statistics page by accessing following address: ```http://10.10.1.10:8080```. Default credentials are - user: ```admin``` password: ```password```. 43 | 44 | Open your web browser, application is available at ```http://10.10.1.20/8080/```. 45 | 46 | - - - 47 | 48 | **1**: Since v.1.7.0 Vagrant has started generating separate SSH key for each machine making provisioning process more difficult. In prior version there was only a single key for all of the machines - ```~/.vagrant.d/insecure_private_key```. After v.1.7.0 each machine has its own key located in ```.vagrant/machines/<>/virtualbox/private_key```. For further details see: [Using Vagrant and Ansible: Running Ansible Manually](http://docs.ansible.com/guide_vagrant.html#running-ansible-manually) 49 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | 8 | # Virtual hosts used for Devoxx presentation 9 | hosts = { 10 | :app1 => { :name => "app1", :address => "10.10.2.20" }, # application server #1 11 | :app2 => { :name => "app2", :address => "10.10.2.21" } # application server #2 12 | } 13 | 14 | # Host setup template 15 | hosts.each do |host, params| 16 | config.vm.define "#{ params[:name] }" do |host| 17 | host.vm.box = "jimmidyson/centos-7.1" 18 | host.vm.box_version = "= 1.2.6" 19 | #host.vm.box = "Centos-6.5-minimal-x86_64-20140116" 20 | #host.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box" 21 | 22 | host.vm.provider :virtualbox do |vb| 23 | vb.customize [ 24 | "modifyvm", :id, 25 | "--name", "kansible-springboot-demo-#{ params[:name] }", 26 | "--memory", 512, 27 | "--cpus", 1, 28 | ] 29 | end 30 | host.vm.network :private_network, ip: "#{ params[:address] }" 31 | host.vm.hostname = "#{ params[:name] }.kansible-springboot-demo" 32 | #host.vm.provision "shell", inline: "sudo yum -y install python-httplib2" # Required to use 'uri' Ansible module 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | host_key_checking = False 3 | ; We want to avoid prompt for adding key, therefore we have disabled strict host 4 | ; key checking. For further info see: 5 | ; http://docs.ansible.com/intro_getting_started.html#host-key-checking -------------------------------------------------------------------------------- /group_vars/appservers: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------------------------------- 2 | # Application settings 3 | #--------------------------------------------------------------------------------------------------------- 4 | 5 | # App name 6 | app_name: 'springboot-camel' 7 | 8 | app_owner: '{{ app_name }}' 9 | app_group: '{{ app_name }}' 10 | 11 | app_classifier: '' 12 | 13 | # App home directory 14 | app_home: '/opt/{{ app_name }}-{{ app_version }}{{ app_classifier }}' 15 | 16 | # App version 17 | app_version: '2.2.98-SNAPSHOT' 18 | 19 | # Port on which web applications are served on appservers 20 | app_port: 8080 21 | -------------------------------------------------------------------------------- /inventory: -------------------------------------------------------------------------------- 1 | [appservers] 2 | app1 ansible_host=10.10.2.20 ansible_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/app1/virtualbox/private_key 3 | app2 ansible_host=10.10.2.21 ansible_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/app2/virtualbox/private_key 4 | 5 | [winboxes] 6 | appx ansible_ssh_host=10.10.2.30 ansible_user=vagrant ansible_ssh_pass=mypassword winrm=true 7 | -------------------------------------------------------------------------------- /kubernetes/README.md: -------------------------------------------------------------------------------- 1 | # kansible resources 2 | 3 | This folder contains the [kubernetes](http://kubernetes.io/) resources for [kansible](https://github.com/fabric8io/kansible). 4 | 5 | There is a folder per ansible host which contains an `rc.yml` to define the [Replication Controller](http://kubernetes.io/v1.1/docs/user-guide/replication-controller.html) to run the kansible pods: 6 | 7 | * [appservers/rc.yml](appservers/rc.yml) 8 | -------------------------------------------------------------------------------- /kubernetes/appservers/rc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: "v1" 3 | kind: "ReplicationController" 4 | metadata: 5 | name: "springboot-demo" 6 | labels: 7 | project: "springboot-demo" 8 | version: "{{ app_version }}" 9 | annotations: 10 | spec: 11 | template: 12 | spec: 13 | containers: 14 | - env: 15 | - name: "KANSIBLE_COMMAND" 16 | value: "{{ app_home }}" 17 | serviceAccountName: "fabric8" 18 | -------------------------------------------------------------------------------- /provisioning/roles/app/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - { role: java } 4 | -------------------------------------------------------------------------------- /provisioning/roles/app/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Creates App user and group in the system 3 | - name: Create App user 4 | user: name={{ app_owner }} createhome=no home={{ app_home }} shell=/sbin/nologin state=present 5 | 6 | # Checks whether App home directory already exists 7 | - name: Check if App is already installed 8 | stat: path={{ app_home }} 9 | register: app_installed 10 | 11 | # Download App package 12 | - name: Download App 13 | get_url: url={{ app_url }} dest=/opt/{{ app_name }}-{{ app_version }} 14 | when: not app_installed.stat.exists 15 | 16 | # Changes ownership of the app 17 | - name: Change permissions of service 18 | file: path=/opt/{{ app_name }}-{{ app_version }} owner={{ app_owner }} group={{ app_group }} mode=555 19 | 20 | # Changes ownership of the app 21 | #- name: Change permissions of service 22 | # file: path=/opt/{{ app_name }}-{{ app_version }} owner={{ app_owner }} group={{ app_group }} mode=500 23 | 24 | # Starts App 25 | #- name: Start App 26 | # service: name={{ app_name }} state=started enabled=yes 27 | -------------------------------------------------------------------------------- /provisioning/roles/app/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # App tgz file name 3 | app_package: '{{ app_name }}-{{ app_version }}{{ app_classifier }}.jar' 4 | 5 | # TODO dirty hack for now!! 6 | app_url: 'https://oss.sonatype.org/content/repositories/snapshots/io/fabric8/quickstarts/{{ app_name }}/2.2.98-SNAPSHOT/{{ app_name }}-2.2.98-20160215.122740-2.jar' 7 | -------------------------------------------------------------------------------- /provisioning/roles/java/files/jre-8u45-linux-x64.rpm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fabric8io/fabric8-ansible-spring-boot/2f802c846fb3ad97bf80687813d097a7f9c7cfdc/provisioning/roles/java/files/jre-8u45-linux-x64.rpm -------------------------------------------------------------------------------- /provisioning/roles/java/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Copies JRE rpm package from control machine to provisioned machine 3 | - name: Copy rpm to provisioned machine 4 | copy: src={{ java_rpm }} dest={{ ansible_env.HOME }} 5 | 6 | # Installs JRE from local rpm using yum 7 | - name: Install JRE 8 | yum: name={{ ansible_env.HOME }}/{{ java_rpm }} state=present 9 | sudo: yes 10 | 11 | # Add JAVA_HOME and JRE_HOME variables to bash profile 12 | - name: Add script setting JAVA_HOME and JRE_HOME 13 | template: src=java.sh.j2 dest=/etc/profile.d/java.sh owner=root group=root mode=0644 14 | sudo: yes 15 | -------------------------------------------------------------------------------- /provisioning/roles/java/templates/java.sh.j2: -------------------------------------------------------------------------------- 1 | {# 2 | This file defines .j2 template for bash script exporting JAVA_HOME and JRE_HOME to bash profile. 3 | #} 4 | 5 | export JAVA_HOME={{ java_home }} 6 | export JRE_HOME={{ jre_home }} 7 | -------------------------------------------------------------------------------- /provisioning/roles/java/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # JRE rpm package file name 3 | java_rpm: 'jre-8u45-linux-x64.rpm' 4 | # JAVA_HOME environment variable value 5 | java_home: '/usr/java/jre1.8.0_45' 6 | # JRE_HOME environment variable value 7 | jre_home: '{{ java_home }}' 8 | -------------------------------------------------------------------------------- /provisioning/site.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Playbook for environment provisioning 3 | # Provisions application servers with the App 4 | - name: Provision appservers 5 | hosts: appservers 6 | roles: 7 | - { role: app, sudo: yes } # Depends on java role 8 | -------------------------------------------------------------------------------- /vault.yml: -------------------------------------------------------------------------------- 1 | $ANSIBLE_VAULT;1.1;AES256 2 | 65363539303330323362613263643365633230616263373932663337643337363237386563313731 3 | 6538376665306532623365616535313637626230636332380a343838643864613030623966393038 4 | 36356561663733383465656139323461643066316535313836303532323334666536323162656531 5 | 3237363436333762360a383466363134313336326332393930626237326537383130333736663033 6 | 34323864306437366263383336306132626330643361326139623832383936633737346536623436 7 | 62323335613734396335376664386438333832316638303863633135353835353639346133633236 8 | 30636439303237666664626336333562396135336236653066343961623564623065326564343065 9 | 36313031626261623237376532343537623238656531326133363933383034373837316633663734 10 | 3862 11 | --------------------------------------------------------------------------------