Skip to content

Instantly share code, notes, and snippets.

@svyatov
Created November 6, 2012 18:32
Show Gist options
  • Save svyatov/4026576 to your computer and use it in GitHub Desktop.
Save svyatov/4026576 to your computer and use it in GitHub Desktop.
Update apt cache once per play
---
- apt: update-cache=yes
only_if: is_unset("$apt_cache_updated")
register: apt_cache_updated
@svyatov
Copy link
Author

svyatov commented Nov 6, 2012

Put this file to something like playbooks/global_tasks and use like so...

  tasks:
  - include: global_tasks/apt_update_cache.yml

...wherever you want - cache updating will be performed just once.

If you need to force update (after adding new repo for example) - just use apt module as usual instead of this include:

tasks:
- apt_repository: repo=ppa://nginx/stable
- apt: update-cache=yes

By the way, the case above can be impoved this way:

tasks:
- apt_repository: repo=ppa://nginx/stable
  register: nginx_repo_added
- apt: update-cache=yes
  only_if: "${nginx_repo_added.changed}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment