Managing apt_repository additions

Something I’m trying to work out how to manage, and I’m wondering how other people are doing it (I’m using the latest from Git atm).

If I have something like the following:


- name: Add Neo4j Repository - Debian
apt_repository: repo='deb [http://debian.neo4j.org/repo](http://debian.neo4j.org/repo) stable/'
- name: install neo4j
apt: pkg=neo4j

It fails, because the neo4j package can’t be found (which makes sense), as the there hasn’t been an apt-get update to refresh the package list.

This means, I have to write something like this:


- name: Add Neo4j Repository - Debian
apt_repository: repo='deb [http://debian.neo4j.org/repo](http://debian.neo4j.org/repo) stable/'
- name: install neo4j
apt: pkg=neo4j update_cache=yes cache_valid_time=43200

Which works, but I’m not a huge fan, simply because it could inadvertently upgrade neo4j when I’m not ready for it yet on a deploy, but updating the PPA when I’ve not really wanted it to.

Using a handler doesn’t work (on change when the new repository gets added), as that runs at the end of the playbook, which is too late.

I swear that it didn’t used to be this way, that adding an apt_repository would update as well, and the new packages would be found. I could be wrong though.

How are other people dealing with this?

Does apt_repository need a ‘update=true’ property that fires off an update immediately, when it does initially get added?

Be keen to hear people’s thoughts.

Mark

Using a handler doesn't work (on change when the new repository gets added),
as that runs at the end of the playbook, which is too late.

As of Ansible 1.2, you can explicitly flush handlers, so all the
handlers that were notified up to that point get run. You can do this
with a "meta: flush_handlers" as described on
http://www.ansibleworks.com/docs/playbooks.html.

This is how I deal with these kinds of situations.

Aha! I hadn’t seen that.

Thanks, that will work nicely.

Mark