# cache\_valid\_time doesn't work

**URL:** <https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063>\
**Category:** Ansible Developer\
**Created:** [December 4, 2013, 6:45pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063 "2013-12-04T18:45:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SLS](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SLS](https://forum.ansible.com/u/SLS)\
**Post date:** [December 4, 2013, 6:45pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/1 "2013-12-04T18:45:32Z")

</div>

Hi there,

I can’t get the cache\_valid\_time parameter to take. Below is the relevant section of my playbook.

- name: ensure apache installed  
apt: pkg={{ item }} state=present update\_cache=yes cache\_valid\_time=3600  
with\_items:
- apache2  
notify:
- restart apache

I’m running this via a local vagrant box and am wondering if this has anything to do with the problem. Each time I run ‘vagrant provision’, cache\_valid\_time is ignored and the cache is updated.

Thanks.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 4, 2013, 7:12pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/2 "2013-12-04T19:12:56Z")

</div>

> I can't get the cache\_valid\_time parameter to take. Below is the relevant  
> section of my playbook.
> 
> - name: ensure apache installed  
> &nbsp;&nbsp;&nbsp;&nbsp;apt: pkg={{ item }} state=present update\_cache=yes  
> cache\_valid\_time=3600  
> &nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- apache2  
> &nbsp;&nbsp;&nbsp;&nbsp;notify:  
> &nbsp;&nbsp;&nbsp;&nbsp;- restart apache
> 
> I'm running this via a local vagrant box and am wondering if this has  
> anything to do with the problem. Each time I run 'vagrant provision',  
> cache\_valid\_time is ignored and the cache is updated.

This parameter makes the module check the timestamp on two paths:

- first /var/lib/apt/periodic/update-success-stamp  
- and if that was not available, /var/lib/apt/lists​​/

And compares that timestamp to the current time to caclulate the that  
valid\_time.

Can You check on you host if you have those files on those locations?

Serge

---

<div class="post-metadata">

**Author:** ![SLS](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SLS](https://forum.ansible.com/u/SLS)\
**Post date:** [December 4, 2013, 7:40pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/3 "2013-12-04T19:40:40Z")

</div>

Thanks for the quick response-

-rw-r–r-- 1 root root 0 May 5 2013 update-success-stamp  
and /var/lib/apt/lists/ has many _.ubuntu.com\_ubuntu\_dists\_raring-_ files with varying dates (ranging from Oct 2012 to today).

My results for ‘date’ are Wed Dec 4 19:26:56 UTC 2013.

If I’m understanding correctly, it’s updating the cache because the update-success-stamp is there with a \> 3600 second timestamp (which is how it should work). So the question is why isn’t that timestamp getting updated.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 4, 2013, 7:43pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/4 "2013-12-04T19:43:21Z")

</div>

​This is (at least on Ubuntu, not sure if Debian or others have this) updated by

$ cat /etc/apt/apt.conf.d/15update-stamp

APT::Update::Post-Invoke-Success {“touch /var/lib/apt/periodic/update-success-stamp 2\>/dev/null || true”;};

Do you have that config snippet?

Serge

---

<div class="post-metadata">

**Author:** ![SLS](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SLS](https://forum.ansible.com/u/SLS)\
**Post date:** [December 4, 2013, 7:44pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/5 "2013-12-04T19:44:50Z")

</div>

Yes. It is there.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 4, 2013, 7:49pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/6 "2013-12-04T19:49:44Z")

</div>

Does the timestamp get updated when you manually do an update?​

​Either way, seems not to be a bug in that module.

---

<div class="post-metadata">

**Author:** ![SLS](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SLS](https://forum.ansible.com/u/SLS)\
**Post date:** [December 4, 2013, 8:31pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/7 "2013-12-04T20:31:21Z")

</div>

Agreed. This not an ansible module issue, but a Vagrantfile configuration fix. The problem was with the V

A manual update showed the errors and since it wasn’t successful, the file didn’t get touched.

Err [http://security.ubuntu.com](http://security.ubuntu.com) raring-security Release.gpg  
Could not resolve ‘[security.ubuntu.com](http://security.ubuntu.com)’  
Fetched 958 kB in 4min 19s (3,692 B/s)

Reading package lists… Done

W: Failed to fetch [http://security.ubuntu.com/ubuntu/dists/raring-security/Release.gpg](http://security.ubuntu.com/ubuntu/dists/raring-security/Release.gpg) Could not resolve ‘[security.ubuntu.com](http://security.ubuntu.com)’  
W: Some index files failed to download. They have been ignored, or old ones used instead.

I added the following to my Vagrantfile and it worked like a charm.

config.vm.provider :virtualbox do |virtualbox|  
virtualbox.customize [“modifyvm”, :id, “–natdnshostresolver1”, “on”]  
end

Thanks for all your help.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 4, 2013, 8:48pm UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/8 "2013-12-04T20:48:57Z")

</div>

​Hm, makes me wonder if we should let apt give some feedback (as in,  
setting some return value) when that happens? If I update for adding a  
particular repo I just added, I would want to know it fails.

​

---

<div class="post-metadata">

**Author:** ![SLS](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@SLS](https://forum.ansible.com/u/SLS)\
**Post date:** [December 5, 2013, 2:05am UTC](https://forum.ansible.com/t/cache-valid-time-doesnt-work/14063/9 "2013-12-05T02:05:12Z")

</div>

Yes, that would have probably helped. Thanks again.
