---
# Copyright 2016, Logan Vig <logan2211@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Check apt last update file
  stat:
    path: /var/cache/apt
  register: apt_cache_stat
  tags:
    - unbound-apt-packages

- name: Update apt if needed
  apt:
    update_cache: yes
  when: "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}"
  tags:
    - unbound-apt-packages

- name: Install unbound packages
  apt:
    pkg: "{{ item }}"
    state: "{{ unbound_package_state }}"
  register: install_packages
  until: install_packages | success
  retries: 5
  delay: 2
  with_items: "{{ unbound_packages }}"
  tags:
    - unbound-apt-packages

---
# Copyright 2016, Logan Vig <logan2211@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Check apt last update file
  stat:
    path: /var/cache/apt
  register: apt_cache_stat
  tags:
    - unbound-apt-packages

- name: Update apt if needed
  apt:
    update_cache: yes
  when: ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > cache_timeout
  tags:
    - unbound-apt-packages

- name: Install unbound packages
  apt:
    pkg: "{{ item }}"
    state: "{{ unbound_package_state }}"
  register: install_packages
  until: install_packages | success
  retries: 5
  delay: 2
  with_items: "{{ unbound_packages }}"
  tags:
    - unbound-apt-packages

Fix apt update cache conditional
Fix apt update cache conditional

This terribly written conditional worked in ansible <2.2.
Now it's properly broken and this commit should fix it.

Please note that this trick is NOT required anymore in
ansible 2.2, so it's possible to remove these tasks
if meta/main.yml moves to a minimum version of 2.2.
