Skip to main content

Understand Core Components of Ansible – Software Management

Hands-On Lab

 

Photo of Rob Marti

Rob Marti

Linux Training Architect I in Content

Length

00:15:00

Difficulty

Beginner

One of the drivers to automate is to make sure that all the required software is installed and software that isn't required isn't installed. While that seems easy enough, any task repeated over a thousand servers is going to be difficult. This lab will go through Ansible's method of software management to ease that Adminsitrator's mind.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Understand Core Components of Ansible - Software Management

Introduction

One of the drivers to automate is to make sure that all the required software is installed, and software that isn't required isn't installed. While that seems easy enough, any task repeated over a thousand servers is going to be difficult. This lab will go through Ansible's method of software management to ease that Adminsitrator's mind.

The Scenario

We're in the midst of a proof of concept project. We've currently got a server that must have httpd installed, and must not have tcpdump installed. To prove that Ansible can do this, we're going to use the yum module to perform both the httpd installation and the tcpdump removal, if it happens to be installed.

Logging In

Use the credentials provided on the hands-on lab page to get into Server1 to begin with. Since we need root privileges, let's just run sudo -i right off and become root.

Install httpd Using Ansible

Let's first check to see if httpd is installed:

rpm -q httpd

It's not, so we'll have to do it. The easiest way to install httpd would be the following command:

ansible -m yum -a "name=httpd state=present" localhost --become

We have to use --become because we're set up to connect using the ansible user which doesn't have access to install software.

After an authenticity prompt, and a few seconds of waiting, we'll see some output. This shows that Ansible installed httpd, along with all of the other software dependencies.

Remove tcpdump Using Ansible

Now we've got to see if tcpdump is installed, and remove it if it is. Just like with httpd, let's query:

rpm -q tcpdump

It's installed, so we've got to remove it. The easiest way to remove tcpdump is this command:

ansible -m yum -a "name=tcpdump state=absent" localhost --become

Here again, we have to use --become because we're set up to connect using the ansible user which doesn't have access to install software.

Conclusion

We can run these two commands again (installing httpd and removing tcpdump), but both will return a Nothing to do type message, because we've accomplished our goal. Congratulations!