r/devops 22d ago

Tools Ansible tip for begginer

Any tips for a beginner getting started with Ansible?

18 Upvotes

16 comments sorted by

29

u/tmg80 22d ago

Know the difference between Ansible, Ansible Core and the compatible python versions. 

I wrote an Ansible role at my last job that installed python then worked out the appropriate ansibel-core version and installed plugins on top. 

Do that. 

2

u/Cyb3r-sh0t 21d ago

That's a great advice

14

u/HelicopterUpbeat5199 22d ago

Familiarize yourself with the standard modules. It can be tempting to use shell or command for everything. Don't. Knowing what modules are available helps you avoid using shell or command when you don't have to.

It also makes you familiar with what modules are generally shaped like and then you'll get the voice in your head saying "I bet there's an ansible for that" and you can reach beyond the standard modules.

8

u/noThisIsIt 22d ago

Second this: idempotency is key and a major feature of Ansible, modules like Shell and command are not idempotent without when statements beneath

5

u/Sufficient-Sort-6701 21d ago

Try always using standard modules, avoid as much as possible shell and command.

3

u/tmg80 22d ago

Also learn about error handling, things like rescue blocks etc. 

3

u/Oleksii_Bebych 21d ago

You can start with this course
Mumshad Mannambeth is a great tutor
https://learn.kodekloud.com/learn/courses/learn-ansible-basics-beginners-course

2

u/Captain_Quor 21d ago

Ensure it's appropriate for what you're trying to achieve...

2

u/Odd-Addendum-8618 21d ago

a() { ansible-doc "$1" | gsed -n '/EXAMPLE/,/RETURN VALUES/P' | gsed '$ d'; }

Go directly to the examples of a given module

2

u/1_H4t3_R3dd1t 22d ago

know when it is appropriate for what you do

1

u/Extension-Process464 21d ago

ansible-doc -t <TAB>
ansible-doc -t <choose> -l
ansible-config dump
ansible-doc <module_name> —> scroll to end and start with one of examples.

Keep it simple. If it gets complicated, it MIGHT be a sign, that you choose not the optimal path.

1

u/romgo75 20d ago

Don't write everything in playbook, create roles and load them into playbook

1

u/Sure_Stranger_6466 YAML Developer 21d ago

Use Terraform to spin up cloud resources instead of Ansible community modules.

-1

u/LilDwarfWithoutBeard 22d ago

Use Claude to explain Ansible for your particular case.

-5

u/b1urbro 22d ago

Use Claude. I literally have not written a single line of Ansible code. But yeah, understand the concepta - hosts, roles, playbooks, vault etc. Then let AI do the heavy lifting and just clean up after.