From ae00b93ebcb80b4a157f86f1d748fb6ac63e44eb Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Mon, 15 Aug 2016 12:38:33 +0100 Subject: [PATCH] Ensure that apt cache is up to date before installing packages Change-Id: I6db566bc0a1e3a9d2ad423389522f1c1c418d07c --- defaults/main.yml | 3 +++ tasks/pre_install.yml | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 70d3117..795e28d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -41,6 +41,9 @@ pip_required_pip_packages: - ndg-httpsclient # SSL SNI support - requests # SSL SNI support +## APT Cache options +cache_timeout: 600 + # Validate Certificates when downloading pip. May be set to "no" when proxy server # is intercepting the certificates. pip_validate_certs: "yes" diff --git a/tasks/pre_install.yml b/tasks/pre_install.yml index d3eb039..1683fec 100644 --- a/tasks/pre_install.yml +++ b/tasks/pre_install.yml @@ -25,6 +25,23 @@ when: - ansible_pkg_mgr == 'yum' +#TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache +#when https://github.com/ansible/ansible-modules-core/pull/1517 is merged +#in 1.9.x or we move to 2.0 (if tested working) +- name: Check apt last update file + stat: + path: /var/cache/apt + register: apt_cache_stat + when: + - ansible_pkg_mgr == 'apt' + +- name: Update apt if needed + apt: + update_cache: yes + when: + - ansible_pkg_mgr == 'apt' + - "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}" + - name: Install apt packages apt: pkg: "{{ item }}"