Quickly Create An Ansible Task (Part 1)

Ansible is a great, agentless, automation tool any linux SYSADMIN needs to learn and implement NOW!

Especially if you have at least 1/2 a dozen or more linux boxes.

In this post, I’m assuming you already have Ansible installed and configured (ansible.cfg).

This not a introduction to Ansible, this is specifically for current Ansible users.

We’re going to take the bash command

apt-get install nano

 

And convert it to an Ansible command (there’s actually 3 different kindz!)

BRAINSTORMING

Every Ansible task has a syntax (duh! I know).

But BEFORE we us it, lettuce understand it and visualize it FIRST!!

In our mind’s-eye and with pencil and paper..all one-in-the-same IMHO.

Below is my own visualization of any Ansible command.

This representation is totally arbitrary and is just how I “see it”:

<module_name>
<parameter1>=<value1>
<parameter2>=<value2>
...
<parameterN>=<valueN> 

 

Now, it just so happens that Ansible has a module specifically for ‘apt-get’ commands

If we take what Ansible provides, and again, visualize it, we get something like this:

apt
allow_unauthenticated=[no|yes]
autoclean=[no|yes]
autoremove=[no|yes]
...
upgrade=[dist|full|no|safe|yes]

 

Remember, we have not written any Ansible code yet. We are still visualizing and brainstorming. Which is probably the most important part of this entire process anyway.

Next, we will select only that parameters and values we needs for our particular purpose.

 

apt
name=nano
state=absent

 

SUMMARY (So far..)

We took our original bash command:

apt-get install nano

and visualized it according to Ansible’s module page and got:

apt
name=nano
state=absent

Now that we have this visualization, the rest of our mission becomes 1000x easier.

We will take our visualization and transform it into valid Ansible code in our next post.

And because we did most of the cognitive heavy-lifting upfront: brainstorming!

The rest of our work, writing actual Ansible syntax, becomes a lot easier.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s