Setting up a Server for Ansible

Ansible is a great tool for automation and configuration management. Maybe you heard already about Chef and Puppet. Ansible is in the same field, but with a much simpler approach. The big advantage of Ansible is that you don’t need a central master server for it and you don’t need to install an “Ansible” client on the servers at all. Ansible only needs to be installed on your local machine and it works completely via SSH. AnsibleLogo_transparent_web Although you don’t need to install a client on the server, Ansible makes a couple assumptions about the server. Ansible assumes that the server is accessible via SSH. That’s the only real requirement. In the Playbooks you can configure username and password to access the server.

However life becomes much easier if we can assume that you:

  • have a user on the system with username “ubuntu”.
  • have the ssh daemon up and running on the server.
  • be able to login as user “ubuntu” to the server via ssh without password.
  • be able to run sudo su without password popup.

All this assumptions are default on AWS EC2 instances. If you setup a new server somewhere else you should take care of this. This blog post describes how to ensure this assumptions on Ubuntu 14.04.

User ubuntu

If you create a new virtual machine make sure that the default user is ubuntu. If you have already a linux instance up and running you can add a new user like this:

sudo adduser ubuntu

SSH Daemon

This command will return the status of the SSH daemon:

sudo service ssh status

If the feedback is that the service ssh is unknown you can install the SSH Server with this command:

sudo apt-get install openssh-server

Now try again the first command. It should response with status running.

Login without password

Assuming you have already a public/private key pair and the public key on your development machine is under .ssh/id_rsa.pub you can achieve login to the server without password with this 2 commands:

ssh ubuntu@IP_ADDRESS mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh ubuntu@IP_ADDRESS 'cat >> .ssh/authorized_keys'

Replace “IP_ADDRESS” with the IP address of your server! The commands above will still require that you type in your password, but after that you should be able to login to the server without password. Try:

ssh ubuntu@IP_ADDRESS

The full instructions can be found here.

sudo su without password

Simply run this command on the server:

sudo visudo

And add this line to the bottom of the file:

ubuntu ALL=(ALL) NOPASSWD: ALL

Now logout and login again as user ubuntu to the server. Try:

sudo su

Now you should be root on the server. For more questions check out this page.

Done

If you executed the steps above your server is ready for Ansible. Now you can point Ansible Playbooks to your server and use it for provisioning. I’m using Ansible since 2 years together with Docker for the VersionEye Project and so far I really like it!

Docker Introduction

Docker is one of the most promising technologies these days. It is a container technology based on Linux. A very lightweight form of virtualization. Docker containers can be as small as 50 MB. Much smaller than traditional VMs.

The Docker project was started in March 2013 by dotCloud. In the mean while the makers of dotCloud sold dotCloud to CloudControl and raised $55 Million to focus only on the Docker development.

Check out my slides to “Docker Introduction”. I did this talk at the Webmontag in Mannheim. Feedback was very good.

I’m using Docker since beginning of 2014 in production and I love it. It’s a great technology!

Global Variables with Ansible

Ansible is a great tool for IT automation. It’s similar to Chef and Puppet, just better!¬†

I wrote here already an introduction to Ansible. In Ansible you have roles and playbooks. A playbook can contain several roles. Inside a role you can have tasks, files, handlers and variables. But sometimes you want to use a variable across multiple roles. Unfortunately Ansible doesn’t have really a concept of global vars, but there is a trick ūüėȬ†

You can define group variables for ALL groups, that is indeed like a global variable. I manage my Ansible code in a git repo. The file tree looks like this: 

infrastructure
  \__ group_vars
     \__ all
        \__ vars_file.yml
  \__ roles 
  \__ ansible.cfg
  \__ site.yml
  \__ hosts

 

The variables defined in “group_vars/all/vars.yml” are accessible from ALL roles!¬†

Introduction to Ansible

Ansible is a great tool for IT automation.

I’m using Ansible to manage the whole infrastructure for VersionEye. Currently I have 36 roles and 15 playbooks defined for VersionEye. I can setup the whole infrastructure with 1 single command! Or just parts of it. I even use Ansible for deployments. Deploying the VersionEye crawlers into the Amazon Cloud is 1 single command for me. And I even rebuild the capistrano deployment process for Rails apps with Ansible.

AnsibleLogo_transparent_web

I just wrote an introduction to Ansible on the VersionEye Blog. Check it out here.