• Stars
    star
    2,170
  • Rank 21,251 (Top 0.5 %)
  • Language
    Shell
  • License
    Other
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ansible tutorial

Ansible tutorial

This tutorial presents Ansible step-by-step. You'll need to have a (virtual or physical) machine to act as an Ansible node. A Vagrant environment is provided for going through this tutorial.

Ansible is a configuration management software that lets you control and configure nodes from another machine. What makes it different from other management software is that Ansible uses (potentially existing) SSH infrastructure, while others (Chef, Puppet, ...) need a specific PKI infrastructure to be set up.

Ansible also emphasizes push mode, where configuration is pushed from a master machine (a master machine is only a machine where you can SSH to nodes from) to nodes, while most other CM typically do it the other way around (nodes pull their config at times from a master machine).

This mode is really interesting since you do not need to have a 'publicly' accessible 'master' to be able to configure remote nodes: it's the nodes that need to be accessible (we'll see later that 'hidden' nodes can pull their configuration too!), and most of the time they are.

This tutorial has been tested with Ansible 2.9.

We're also assuming you have a keypair in your ~/.ssh directory.

Quick start

  • install Vagrant if you don't have it
  • install ansible (preferably 2.10.5+ and using pip+virtualenv)
  • vagrant up
  • goto step-00

Complete explanations

Installing Ansible

The reference is the installation guide, but I strongly recommend the Using pip & virtualenv (higly recommended !) method.

Using pip & virtualenv (higly recommended !)

The best way to install Ansible (by far) is to use pip and virtual environments.

Using virtualenv will let you have multiple Ansible versions installed side by side, and test upgrades or use different versions in different projects. Also, by using a virtualenv, you won't pollute your system's python installation.

Check virtualenvwrapper for this. It makes managing virtualenvs very easy.

Under Ubuntu, installing virtualenv & virtualenvwrapper can be done like so:

sudo apt install python3-virtualenv virtualenvwrapper python3-pip
exec $SHELL

You can then create a virtualenv:

mkvirtualenv ansible-tuto
workon ansible-tuto

(mkvirtualenv usually switches you automatically to your newly created virtualenv, so here workon ansible-tuto is not strictly necessary, but lets be safe).

Then, install ansible via pip:

pip install ansible==2.7.1

(or use whatever version you want).

When you're done, you can deactivate your virtualenv to return to your system's python settings & modules:

deactivate

If you later want to return to your virtualenv:

workon ansible-tuto

Use lsvirtualenv to list all your virtual environments.

From source (if you want to hack on ansible source code)

Ansible devel branch is always usable, so we'll run straight from a git checkout. You might need to install git for this (sudo apt-get install git on Debian/Ubuntu).

git clone git://github.com/ansible/ansible.git
cd ./ansible

At this point, we can load the Ansible environment:

source ./hacking/env-setup

From a distribution package (discouraged)

sudo apt-get install ansible

From a built deb package (discouraged)

When running from an distribution package, this is absolutely not necessary. If you prefer running from an up to date Debian package, Ansible provides a make target to build it. You need a few packages to build the deb and few dependencies:

sudo apt-get install make fakeroot cdbs python-support python-yaml python-jinja2 python-paramiko python-crypto python-pip
git clone git://github.com/ansible/ansible.git
cd ./ansible
make deb
sudo dpkg -i ../ansible_x.y_all.deb (version may vary)

Cloning the tutorial

git clone https://github.com/leucos/ansible-tuto.git
cd ansible-tuto

Running the tutorials interactively with Docker

You can run the tutorials here interactively including a very simple setup with docker.

Check this repository for details.

Using Vagrant with the tutorial

It's highly recommended to use Vagrant to follow this tutorial. If you don't have it already, setting up should be quite easy and is described in step-00/README.md.

If you wish to proceed without Vagrant (not recommended!), go straight to step-01/README.md.

Contents

Terminology:

  • command or action: ansible module executed in stand-alone mode. Intro in step-02.
  • task: combines an action (a module and its arguments) with a name and optionally some other keywords (like looping directives).
  • play: a yaml structure executing a list of roles or tasks over a list of hosts
  • playbook: yaml file containing multiple plays. Intro in step-04.
  • role: an organisational unit grouping tasks together in order to achieve something (install a piece of software for instance). Intro in step-12.

Just in case you want to skip to a specific step, here is a topic table of contents.

Contributing

Thanks to all people who have contributed to this tutorial:

(and sorry if I forgot anyone)

I've been using Ansible almost since its birth, but I learned a lot in the process of writing it. If you want to jump in, it's a great way to learn, feel free to add your contributions.

The chapters being written live in the writing branch.

If you have ideas on topics that would require a chapter, please open a PR.

I'm also open on pairing for writing chapters. Drop me a note if you're interested.

If you make changes or add chapters, please fill the test/expectations file and run the tests (test/run.sh). See the test/run.sh file for (a bit) more information.

When adding a new chapter (e.g. step-NN), please issue:

cd step-99
ln -sf ../step-NN/{hosts,roles,site.yml,group_vars,host_vars} .

For typos, grammar, etc... please send a PR for the master branch directly.

Thank you!

More Repositories

1

ansible-rbenv-playbook

Ansible playbook with roles looping for multiple ruby versions installation using rbenv
Shell
42
star
2

ansible-pxc

Percona XtraDB Cluster role
Jinja
26
star
3

ansible-blue-green

Blue-green deployement for Ansible
Shell
14
star
4

ansible-strongswan-server

Ansible strongswan role
Shell
12
star
5

ansible-gcloud

Google Cloud SDK install role (Ubuntu) - Archive, see ->
8
star
6

cats

cats is a cat like utility for serial ports
C
7
star
7

ansible-proxysql

Ansible proxysql role
Shell
6
star
8

ansible-percona

Percona server role
Shell
6
star
9

ansible-s3cmd

s3cmd ansible role
5
star
10

ansible-pacemaker-corosync

Ansible role for corosync + pacemaker
5
star
11

ramaze-fnordmetric

Ramaze Fnordmetric Helper
Ruby
5
star
12

ansible-sshd

Ansible sshd role
Pawn
4
star
13

lab-proxysql

ProxySQL docker compose lab
Shell
4
star
14

ansible-haproxy-blue-green

HAProxy blue-green deployments using backend switching
4
star
15

ansible-rsync-backup

Simple rsync-based differentiel backup script and playbook
Shell
3
star
16

covina

docker compose setup with grafana, influxdb to display coronavirus graphs per country
Go
3
star
17

mysql_auth

SQUID authentication helper for MySQL database stored credentials
C
3
star
18

filedrop

Small file upload application
Python
2
star
19

ansible-postfix-to-mandrill

Ansible role that installs postfix as a Mandrill relayer
Shell
2
star
20

ansible-hosts

Populates hosts file with hosts from the current play
2
star
21

ansible-dse

Datastax Ansible role
Shell
2
star
22

vtt-route

Subscription forms for challengevttroute.fr
Ruby
2
star
23

ansible-lsyncd-fanout

Ansible role that replicates multiple directories to multiple targets, using lsyncd 2.x.
2
star
24

dotfiles

My dotfiles
Ruby
2
star
25

sample_blog

Sample blog created from tutorial
Ruby
1
star
26

ansible-tuto-demosite

Demo site for antible-tuto
PHP
1
star
27

museobutton

Code pour bouton museographique
C
1
star
28

ansible-twemproxy

Twemproxy role for ubuntu 16.04
Shell
1
star
29

ansible-postfix

Ansible postifx role
Shell
1
star
30

ansible-haproxy

Ansible haproxy 1.7+ role
Shell
1
star
31

erabackup

ERASME
1
star
32

museomix2011

ERASME contributed code for museomix2011 projects
Ruby
1
star
33

ansible-influxdb

Ansible influxdb role
Jinja
1
star
34

earthmapper

Tile proxy for GoogleEarth
Ruby
1
star
35

toji

Toji is a Toggl โžก Jira bridge: sync your Toggl entries directly into Jira issues worklog
Go
1
star
36

sqlplus.vim

sqlplis.vim github clone (http://www.vim.org/scripts/script.php?script_id=2821)
Vim Script
1
star
37

ansible-nfs-server

Ansible NFS server role
Shell
1
star