<commit_before>---
layout: post
title: Haaaaaave you met... Ansible?
categories: [Python, Ansible, Deploy]
tags: [code, python, ansible, deploy]
comments: true
description: Get a quick overview of Ansible with a small example.
---

![met_ansible_yet?](/assets/images/have-you-met-ansible.jpg)


Ansible (ansible.com) is a tool of choice to automate anything you'd like for your servers. And guess what? "- What?" It's written in Python. Hooray! :tada:

It took me waaay too long to realize it was THE tool I needed. But there are new things everyday in our industry, keeping up is hard. At Europython2017, I had the opportunity to witness how well Ansible spread within our community. Everyone seems to love it and I'm late to the party.

What you need to know right now : Ansible is dead simple to use and can do magic for you. Most of the time, you don't have to hack a single thing.
It's like the phone marketplaces :phone:, if you want something, there are certainly apps for that. Hum, sorry, here, it's called a module but it's all the same.

On the Ansible website, you may notice something called "Ansible Tower" but let's stick to the free part and the pure Ansible part.

Let's take together a dead simple example to discover Ansible: nginx installation on a remote server.


Install
-------
Before anything which may seem witty, we need to install it!
You can see the [official installation documentation](http://docs.ansible.com/ansible/latest/intro_installation.html) for a more detailled approach. As I'm working on an ubuntu machine, the following examples assume you have a similar setup or you have the ability to "translate" the commands.


Via apt ubuntu :

```
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
```

:gift: That's it.

First blood
-----------

Let's create a file with server lists called `hosts`:

```INI
[web]
192.168.33.10
192.168.33.11
192.168.33.12

[database]
192.168.33.13
192.168.33.14
```

It allows us to run recipes for groups and list servers within each group. Let's start with a more simple "hosts" file containing only the address of one server of mine:


```INI
[web]
192.168.33.10
```

Ansible is about creating recipes to do stuff. It's like cooking but with code.
A recipe is called a `playbook` and is written with `yaml`

```yaml<commit_msg>Update 2017-09-25-ansible.md<commit_after>---
layout: post
title: Haaaaaave you met... Ansible?
categories: [Python, Ansible, Deploy]
tags: [code, python, ansible, deploy]
comments: true
description: Get a quick overview of Ansible with a small example.
---

![met_ansible_yet?](/assets/images/have-you-met-ansible.jpg)


Ansible (ansible.com) is a tool of choice to automate anything you'd like for your servers. And guess what? "- What?" It's written in Python. Hooray! :tada:

It took me waaay too long to realize it was THE tool I needed. But there are new things everyday in our industry, keeping up is hard. At Europython2017, I had the opportunity to witness how well Ansible spread within our community. Everyone seems to love it and I'm late to the party.

What you need to know right now : Ansible is dead simple to use and can do magic for you. Most of the time, you don't have to hack a single thing.
It's like the phone marketplaces :phone:, if you want something, there are certainly apps for that. Hum, sorry, here, it's called a module but it's all the same.

On the Ansible website, you may notice something called "Ansible Tower" but let's stick to the free part and the pure Ansible part.

Let's take together a dead simple example to discover Ansible: nginx installation on a remote server.


Install
-------
Before anything which may seem witty, we need to install it!
You can see the [official installation documentation](http://docs.ansible.com/ansible/latest/intro_installation.html) for a more detailled approach. As I'm working on an ubuntu machine, the following examples assume you have a similar setup or you have the ability to "translate" the commands.


Via apt ubuntu :

```
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
```

:gift: That's it.

First blood
-----------

Files we're going to create can live almost anywhere on your machine. Let's suppose you store them all in one place, maybe in your project root repository or in a folder inside it.

Let's create a file with server lists called `hosts`:

```INI
[web]
192.168.33.10
192.168.33.11
192.168.33.12

[database]
192.168.33.13
192.168.33.14
```

It allows us to run recipes for groups and list servers within each group. Let's start with a more simple "hosts" file containing only the address of one server of mine:


```INI
[web]
192.168.33.10
```

Ansible is about creating recipes to do stuff. It's like cooking but with code.
A recipe is called a `playbook` and is written with `yaml`

```yaml
{'fraction_non_alphanumeric': 0.08341708542713568, 'fraction_numerical': 0.027336683417085426, 'mean_word_length': 4.016129032258065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7458797', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1402, 'n_words': 743}