Simple Ansible

Checking out Ansible for deploying a demo rails application.

Assumptions

  • That you followed steps in my last article
  • You have the IP address and root password to a server somewhere(cloud, vagrant ...etc)

From there we execute the following to install ansible and configure it with our servers ipaddress:

  
sudo yum install ansible
echo 'railsapp ansible_ssh_host=xxx.xxx.xxx.xxx ask_pass' > /etc/ansible/hosts
ansible all -m ping
  

Next we create a playbook that will checkout our rails application and run it on the server.

  
  vim railsapp.playbook
  

Add the following content.

  
---
- hosts: webservers
  tasks:
  - name: install ruby
    yum: pkg=ruby state=latest
  - name: install rubygems
    yum: pkg=rubygems state=latest
  - name: install rails
    gem: name=rails state=latest
  - name: check out application
    git: repo=https://github.com/asdqwex/rails-demo dest=/opt/railsapp
  - name: run rails
    command: rails server chdir=/opt/railsapp
  

Now we need to run the playbook we created.

  
ansible-playbook playbook.yml -f 10
  

And lastly to verify that the application is running we do the following.

  
curl xxx.xxx.xxx.xxx