How to install Ansible and use it to upgade a server.

For this tutorial we will install Ansible 2 on debian jessie.

In order to install the latest version of ansible on debian jessie we will need to compile it from source since the official debian repositories does not support Ansible 2.x yet.

Therefore first we will need to fetch the source of ansible from the repository:

#cd /usr/local/src
#git clone --recursive https://github.com/ansible/ansible.git
#cd ansible
#git fetch --tags
#git checkout v2.0.0.1-1
#git submodule update

Before we start building the ansible we will need to install some dependencies.

#apt-get install asciidoc devscripts build-essential python-setuptools

To install the development packages necesary to generate the Ansible package is needed to generate a temporarly package named ansible-build-deps-depends. This package states dependencies on all the packages that are needed to build the Ansible package.

#make DEB_DIST=jessie debian
#mk-build-deps --root-cmd sudo  --install --build-dep deb-build/jessie/ansible-2.0.0.1/debian/control
#apt-mark auto asciidoc

To generate the actual deb file we used the following command:

#make DEB_DIST=jessie deb

To install the generated deb file we need to run:

#dpkg -i deb-build/jessie/ansible_2.0.0.1-1.git201512071813.cc98528.headsv20007rc2\~jessie_all.deb
#apt-get install -f

Now it's time to configure ansible. To do so we need to edit the /etc/ansible/ansible.cfg file and we need to configure the modules location by changing the following line.

#library=/usr/lib/pymodules/python2.7/ansible/modules/

Now it's time to test if ansible is working. To do so we will run ping against z0z0.me server with password since we did not set up a ssh key between the ansible server and our web server.

#ansible all -i z0z0.me, -m ping -k
SSH password: 
z0z0.me | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

As you see we got back a ping response. That mean the ansible is working and it can be used to configure your servers.
For more tests we will update the webserver using ansible.

#ansible all -i z0z0.me, -m shell -a 'apt-get update' -k
SSH password: 
z0z0.me | SUCCESS | rc=0 >>
Get:1 http://ftp.us.debian.org jessie-updates InRelease [142 kB]
...
Fetched 19.7 MB in 28s (703 kB/s)
Reading package lists...

The above can be achieved while running apt module with update_cache=true option.

# ansible all -i z0z0.me, -m apt -a 'upgrade=yes update_cache=true' -k
SSH password: 
z0z0.me | SUCCESS => {
    "changed": false, 
    "msg": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nInitializing package states...\nWriting extended state information...\nReading task descriptions...\nBuilding tag database...\nNo packages will be installed, upgraded, or removed.\n0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 0 B of archives. After unpacking 0 B will be used.\nWriting extended state information...\nReading package lists...\nBuilding dependency tree...\nReading state information...\nReading extended state information...\nInitializing package states...\nReading task descriptions...\nBuilding tag database...\n", 
    "stderr": "", 
    "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nInitializing package states...\nWriting extended state information...\nReading task descriptions...\nBuilding tag database...\nNo packages will be installed, upgraded, or removed.\n0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 0 B of archives. After unpacking 0 B will be used.\nWriting extended state information...\nReading package lists...\nBuilding dependency tree...\nReading state information...\nReading extended state information...\nInitializing package states...\nReading task descriptions...\nBuilding tag database...\n", 
    "stdout_lines": [
        "Reading package lists...", 
        "Building dependency tree...", 
        "Reading state information...", 
        "Initializing package states...", 
        "Writing extended state information...", 
        "Reading task descriptions...", 
        "Building tag database...", 
        "No packages will be installed, upgraded, or removed.", 
        "0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", 
        "Need to get 0 B of archives. After unpacking 0 B will be used.", 
        "Writing extended state information...", 
        "Reading package lists...", 
        "Building dependency tree...", 
        "Reading state information...", 
        "Reading extended state information...", 
        "Initializing package states...", 
        "Reading task descriptions...", 
        "Building tag database..."
    ]
}

As you can see the server is currently up to day, therefore there was no needed to upgrade anything, Hurray.

In the next post I will use this ansible installation to turn a blank server into a webserver with the website setup.