Fast-Ansible: Ansible Tutorial, Sample Usage Scenarios (Howto: Hands-on LAB)

I want to share the Ansible tutorial, cheat sheet, and usage scenarios that I created as a notebook for myself. I know that Ansible is a detailed topic to learn in a short term, so I gathered useful information and create sample general usage scenarios of Ansible.

This repo covers Ansible with HowTo: Hands-on LABs (using Multipass: Ubuntu Lightweight VMs): Ad-Hoc Commands, Modules, Playbooks, Tags, Managing Files and Servers, Users, Roles, Handlers, Host Variables, Templates, and many details. Possible usage scenarios are aimed to update over time.

Tutorial Link: https://github.com/omerbsezer/Fast-Ansible

Extra Kubernetes-Tutorial Link: https://github.com/omerbsezer/Fast-Kubernetes

Extra Docker-Tutorial Link: https://github.com/omerbsezer/Fast-Docker

Quick Look (HowTo): Scenarios - Hands-on LABs

Table of Contents

Fast-Ansible: Ansible Tutorial, Sample Usage Scenarios (Howto: Hands-on LAB)

33 comments · 97% upvoted · other discussions

comments

anxiousdoubts

Thanks so much for spreading knowledge, this comes just at the right time!

Nicomet

Thank you ! This will help a lot

coolbeaNs92

Great resource!

I've worked with Ansible for a year or so, but I always struggled with some of the concepts like handers and templates.

Really great stuff, well done.

edit

Also, I would just add (it might be in there, but I didn't see it) using Ansible Galaxy is really helpful, if even purely for the directory structure at first. So when you go onto using those more complicated features, it's easier to layout.

Helped me anyhow :)

BunnyReturns_

like handers and templates.

"Handlers are tasks that only run when notified."

Handlers are also available globally and not just your role

Templates I just started with, but in my case I needed to execute a powershell script, but I can't hard code the password in my project, and I can't use Ansible variables in a PS1 file. So I used a template, this allows me to use variables from Ansible in the PS1 file. You can also use it to setup a general config file and just change what you need on demand.

TU4AR

Just as I finished my udemy course...noice.

Parthorax

This is fantastic thank you for sharing

NGL_ItsGood

Ansible is such a great tool, even for hobbyists. I never use it at work but have some handy playbooks that have made backing up and managing my personal stuff almost effortless.

[deleted]

[removed]

NGL_ItsGood

It's not so much that it replaces those things, it's more a matter of configuring them all in one fell swoop without even having to log into the device itself. It's really useful when doing things at scale or doing it repeatedly. Might not be so necessary for a one off thing on one computer. I used to manage much more self hosted stuff, but now I just have a linux laptop and a linux file/media server, and I still use ansible to do things like update authorized_keys, perform updates across both devices at once, change configs, create mount points, do backups, etc.

[deleted]

Red Hat academy is terrible for me trying to learn Ansible, so thanks!!

Gigahades

Great stuff! 👍

k3mic

The Ansible extension for vscode is also fantastic. Built in documentation, linting, yaml indentation, autocomplete, and jinja. You can even configure it to run your playbooks in the same container (execution environment) that Ansible Automation Platform (AWX) uses. Makes for a better test environment in some cases.

[deleted]

there is no lack of tutorials, but to actually create and share with the community, is a next-level stuff...

thank you very much.

gruffi

I haven't used Ansible in a few years, but me from 2015 thanks you enormously!

ADampWedgie

SOLID write up, saving this for sure thank you !

southaussiewaddy

This is awesome! Thanks man

amperages

Is there anything like this from a CI/DevOps/IaC perspective?

transdimensionalmeme

I always bounce off whatever ansible is, it just sounds more complicated than it needs to be.

Can you explain what ansible is and why I want it ?

Is ansible just wget http://mysite.net/script.sh ; Sudo script.sh ?

What does it do more than that which requires infrastructure and yet is worth having ?

theyawner

I've been using it for the past year and it is in a way similar to how you describe it. But one main difference is that I don't have to do my own scripting if there's already a module that does the same thing and presents it in simpler manner. I also don't need to manually wget and run the script on each server. Instead, I just run a playbook from the ansible control server targeting another server or even a group of servers based on a pre-defined inventory.

The only initial hurdle is trying to get the control server to authenticate properly with the target servers. Getting it to work with a web front-end also adds to the complexity.

[deleted]

[removed]

theyawner

For Linux yes. But as I don't have a centralized authentication I still had to manually configure every ssh authentication for every server I needed to add to the inventory. Windows was another matter where it took a bit of trial and error before I got Active Directory authentication to work. And even then I'd still sometimes experience an issue with some of the nodes in my inventory.

senorsmile

Ansible is an idempotent automation system. Rather than procedurally stating the commands you want to run ome after another, you specify the state of all the things. Ansible goes through, step by step, and ensures all of those things comply with the declared state.

Ansible originally was just a competitor to other configuration management systems like puppet and chef, but it quickly grew to be much more then that. Connecting via ssh to control something is only one of dozens of ways. Most Ansible that I write uses modules that rely on api's.

Highsight

I'm a heavy Jenkins user working in the DevOps field. Can you sell me on Ansible? What exactly can it get me that Jenkins can't?

1esproc

They're entirely different. Ansible is a module based automation platform that helps you get a system to a target state. It understands how to do the things you want to do, so you can define those tasks simply without writing all the scaffolding.

A simple example: Want to set your system's hostname?

- hostname:
  name: myserver01

You don't need to concern yourself with what OS/distribution you're setting the hostname on - the hostname module will attempt to autodetect that and use its native method (e.g., hostnamectl on a systemd based system)

TheRidgeAndTheLadder

Fuck yeah bud.

Quality contribution

ub3rb3ck

Commenting for later.

ShowMeYrBits

Thank you!

JS_NYC_208

Thanks!

[deleted]

This is very well made and thank you for introducing multipass. I wasn't aware of this.

vladdrac38

Great contribute, thanks 👍

boxheadmoose

Amazing!! This will come in very handy. Just started playing around with it today :)

afr33sl4ve

I just set up an esxi host in my homelab. Perfect learning sandbox. Thank you!

SiAnK0

Internet privacy is the new gold. I mass deleted all of my posts on Reddit using Redact. It also supports databrokers, Instagram, Twitter, and all major social media platforms.

exultant degree engine mountainous air grandiose fearless apparatus shaggy growth

[deleted]

Thanks very much for this.

LtChachee

Thanks so much and shared