# How to update the package cache only once per playbook run?

**URL:** <https://forum.ansible.com/t/how-to-update-the-package-cache-only-once-per-playbook-run/13175>\
**Category:** Ansible Project\
**Created:** [July 22, 2013, 6:55pm UTC](https://forum.ansible.com/t/how-to-update-the-package-cache-only-once-per-playbook-run/13175 "2013-07-22T18:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Reagan](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@David\_Reagan](https://forum.ansible.com/u/David_Reagan)\
**Post date:** [July 22, 2013, 6:55pm UTC](https://forum.ansible.com/t/how-to-update-the-package-cache-only-once-per-playbook-run/13175/1 "2013-07-22T18:55:59Z")

</div>

Every time I install a package, I want to make sure I have the latest version. That means I need to run apt-get update, or it’s equivalent, before I install the package. Currently I have an 'apt update\_cache=yes" task running before every package install. That results in multiple ‘apt-get update’ calls. Is there a good way to make that only happen once per `ansible-playbook --sudo /etc/ansible/webservices.yml` ?

Would `state=latest` update the cache only once per run?

Would that work with other package management modules, like yum?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 22, 2013, 7:00pm UTC](https://forum.ansible.com/t/how-to-update-the-package-cache-only-once-per-playbook-run/13175/2 "2013-07-22T19:00:14Z")

</div>

I would just put in a common role, but see also the ‘cache\_valid\_time’ option on the apt module.

[http://ansibleworks.com/docs/modules.html#apt](http://ansibleworks.com/docs/modules.html#apt)

---

<div class="post-metadata">

**Author:** ![David\_Reagan](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@David\_Reagan](https://forum.ansible.com/u/David_Reagan)\
**Post date:** [July 22, 2013, 8:52pm UTC](https://forum.ansible.com/t/how-to-update-the-package-cache-only-once-per-playbook-run/13175/3 "2013-07-22T20:52:43Z")

</div>

Thanks, ‘cache\_valid\_time’ helps.

Though, sticking it in the common role is probably the better idea… 🙂
