Hints on Learning Ansible if Scripting\Programming is not your strong suit.


There are Operations folks, like myself, who for one reason or another have never really mastered a scripting language. Not being a natural at scripting\programing you may feel that configuration management tools would be something that you can’t gain proficiency with but thats is not the case, it just takes a little more effort. Below are some strategies that I am using while learning the basics of Ansible.

Read the Docs and take a class, or two

Ansible has great online documentation compared to some other CM systems and there is a lot of good training to be had. I especially found the classes at Linux Academy to be useful

Start small

Often when folks start with CM systems they go right for the big impress the boss stuff, deploying an entire set of systems for example. Trouble is that since they don't know anything they have to Google together a solution and though they achieve the desired result they do not understand much more then before they started. Start small with package installs and service restarts and work your way from there.

Use Playbooks

You may be tempted to use Ansible as a glorified remote execution engine using ad-hoc commands to execute changes on systems, stringing multiple commands to get your final result. Instead write a playbook, even for the simple stuff. This will help with understanding yaml formatting and the structure of plays. Remember this is about learning, latter on a one liner from the cli may be the right answer

Don't use YAML checkers

There are on-line YAML checkers and it is tempting to just copy and paste what you have written into these checkers and jigger stuff around until the result comes back green. Don’t do this, run your playbooks and have them fail, change them, run again and have them fail again (Hopefully in a different way). In this way you will “get it” in a short period of time. If you want to check syntax before you run your playbooks I would recommend ansible-lint

Use modules

You can create functional playbooks by running a sequence of command or shell module plays but you do not get the idempotent (Google it, I had to) component of the other modules and often the modules take a lot of the heavy lifting off your plate. Every time you need to do something see if you can find a module to do it, this will really help you become familiar with module capabilities

Make it idempotent, if you can

If you use the command and shell modules in your playbook try to work to still make the play idempotent. This is good practice but more importantly will force you to review and learn about registering output and using conditionals to make decisions on registered data latter in playbook

Tidbits:

  • Keep your work, even the scraps, in source control, a good way to keep the data on hard learned investigations on the use of with_lines, but also forces you to learn a little bit about source control
  • Spend time learning about variables and variable precedence in ansible
  • If you are using source control than you will want to use ansible-vault, the docs on this are less then great so it make take some effort to get comfortable but it is worth the effort so you can keep your secrets secret
  • If you are a Windows Admin do not despair there are a significant number of Windows modules most of the core modules have Windows equivalents.
  • Read the requirements section on the module pages or be prepared for a lot of pain when trying to get a module to work when you have not installed the pre-reqs on your control system
  • Roles are great and when you get to a certain point you will want to not have to write the same thing again and again and that is where roles will come in to play.


Learning Ansible here as well. I like your advice to start small. It's tempting to try to boil the ocean when you get your hands dirty with a new tool and start imaging the possibilities. Thanks for sharing.

Like
Reply

Hey, thanks for sharing!

Like
Reply

To view or add a comment, sign in

More articles by Thomas Halligan

  • The Risks of being Risk Averse

    A overly risk averse culture has risks and here are a few Progress slows then stops: The overlay of process and…

  • 7 Troubleshooting Tips

    We design systems and processes to be redundant and impervious to failure, but no system or process is perfect. Anyone…

    4 Comments

Others also viewed

Explore content categories