

In some cases, there is no configured repo, so I must specify one to use it. It already exists in my yum configuration. You may have noticed that I used the rhel-7-server-rpms repo in the examples above. The command module runs a given command in parallel on the hosts specified by a host pattern ( all in this case). I could run the job from Example 3 above in parallel using the Ansible ad-hoc mode: $ ansible all -m command -a 'yum -enablerepo=rhel-7-server-rpms install git' Let's say I have the following static inventory file with two groups and four hosts in it that looks like this: When I started with automation, it was easiest to run commands in parallel on my hosts. Instead of going down that rabbit hole, I will show you how to accelerate your work by using Ansible. Of course, I could create a shell script solution for that problem, too. But what if I have hundreds of hosts? That would be a long-running loop! And what if I have to enable different repos depending on whether a host belongs to production or testing? Hosts in testing may use different repos than hosts in production. With this loop, git is installed as a serial job on host1, host2, and host3.

Ssh yum -enablerepo=rhel-7-server-rpms install git So what do I do when it comes to multiple remote hosts? Well, I could use a loop like: $ for HOST in (host1 host2 host3) do Example 3: Configure multiple remote hosts Okay, but how do I add a repo to a remote host, and then install a package there? Well, I could do something like this: $ ssh yum -enablerepo=rhel-7-server-rpms install git I could temporarily enable a repo (if it is currently disabled in the configuration) and install a package from it with the following command: $ sudo yum -enablerepo=rhel-7-server-rpms install git Easy, right? This example runs the commands manually, and it's simple enough for a single host. Example 1: Subscription-Manager and YUMįirst, enable a repo with the subscription-manager and then install a package via yum with the following command: $ sudo subscription-manager repos -enable=rhel-7-server-rpms Anyway, here are some examples of enabling a repo on a single host and installing a package from it.

Well, I guess most of you already know how this works. Add one repo to a host and install a package But first, let me remind you how to do it without Ansible. In this article, I show you how Ansible makes managing hosts easier by adding a package repository (repo) and installing a package from it.
