# Intelligent loop for yum packages installation

**URL:** <https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431>\
**Category:** Ansible Project\
**Created:** [September 7, 2013, 12:36am UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431 "2013-09-07T00:36:04Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Dylan\_Martin](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dylan\_Martin](https://forum.ansible.com/u/Dylan_Martin)\
**Post date:** [October 18, 2013, 7:46pm UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/21 "2013-10-18T19:46:20Z")

</div>

Is yum on the client configured to keep cache & metadata? If it’s throwing all that out, it can take a really long time for each run. Check for keepcache, metadata\_expire and mirrorlist\_expire and possibly others in your /etc/yum.conf as well as each repo’s config on the client.

---

<div class="post-metadata">

**Author:** ![Frederick\_Yankowski](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@Frederick\_Yankowski](https://forum.ansible.com/u/Frederick_Yankowski)\
**Post date:** [May 9, 2014, 4:10pm UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/22 "2014-05-09T16:10:54Z")

</div>

Thank you, Alex! This works great for me in RHEL 6.5. It had been taking several minutes to run “yum state=latest” for just four packages (already installed). Now it finishes in just a few seconds.

I was getting close to giving up on ansible because of the huge delays in every “yum” step. All the repoquery calls done on the managed server were taking forever, even with a local RHEL mirrors and yum caching enabled.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 9, 2014, 5:33pm UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/23 "2014-05-09T17:33:58Z")

</div>

If you are seeing long times with state=latest, I’d suspect you maybe have RHN to blame. I always recommend a local mirror if so. If you aren’t having RHN involved, perhaps you are still using a slow mirror.

---

<div class="post-metadata">

**Author:** ![Frederick\_Yankowski](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@Frederick\_Yankowski](https://forum.ansible.com/u/Frederick_Yankowski)\
**Post date:** [May 12, 2014, 1:20pm UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/24 "2014-05-12T13:20:41Z")

</div>

> We set up a local RHEL mirror just this week, thinking that that would speed up ansible. It didn’t.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 12, 2014, 5:10pm UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/25 "2014-05-12T17:10:53Z")

</div>

Ok, thanks for info.

Probably something that should be addressed on yum’s end as we do need the latest information to decide whether to run certain commands or not.

While it is possible to just run the command and report back what it changed (or didn’t), that’s not Ansible’s way when it can avoid it, and also prevents some check mode capabilities.

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [May 13, 2014, 4:47am UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/26 "2014-05-13T04:47:02Z")

</div>

I realize that this will probably qualify for non-Ansible way, but here’s how I had to resolve similar issue:

1. split playbook into “install” and “setup” whereas install is ran only once in a while if you need to change list of packages installed etc. - resolves issues with RHN etc. setup can be run anytime with any frequency with no ill side-effects
2. For the “setup” I’ve slapped together [https://github.com/droopy4096/ansible-libs/blob/master/library/rpm\_query](https://github.com/droopy4096/ansible-libs/blob/master/library/rpm_query) which I use in place of “yum” actions. This just adds a bit of “insurance” to the “setup” playbook, confirming that packages indeed are there.

while not perfect it gets around all those slow bits of yum, and in our environment packages get to machines sideways (no direct access to internet) thus above split allows for multiple implementations of “install” while keeping the same “setup”.

---

<div class="post-metadata">

**Author:** ![Balamurugan\_Ramasamy](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@Balamurugan\_Ramasamy](https://forum.ansible.com/u/Balamurugan_Ramasamy)\
**Post date:** [March 26, 2015, 4:34pm UTC](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431/27 "2015-03-26T16:34:49Z")

</div>

Hi Frederick/Dylan

I have the same problem. The repo query is being made to every single build of a package, thus making the yum install several mins.  
I did set the keepcache to 1 in /etc/yum.conf. but that did not fix the issue. Could you share what those settings exactly are?

Thanks  
Bala

[Previous page](https://forum.ansible.com/t/intelligent-loop-for-yum-packages-installation/13431.md?page=1)
