cache_valid_time doesn't work

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.

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.

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

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.

​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

Yes. It is there.

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

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

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 raring-security Release.gpg
Could not resolve ‘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 Could not resolve ‘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.

​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.

Yes, that would have probably helped. Thanks again.