# Managing apt\_repository additions

**URL:** <https://forum.ansible.com/t/managing-apt-repository-additions/13379>\
**Category:** Ansible Project\
**Created:** [August 29, 2013, 8:42am UTC](https://forum.ansible.com/t/managing-apt-repository-additions/13379 "2013-08-29T08:42:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Mandel](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Mark\_Mandel](https://forum.ansible.com/u/Mark_Mandel)\
**Post date:** [August 29, 2013, 8:42am UTC](https://forum.ansible.com/t/managing-apt-repository-additions/13379/1 "2013-08-29T08:42:51Z")

</div>

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:

```auto

- 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:

```auto

- 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

---

<div class="post-metadata">

**Author:** ![Nick\_Groenen](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@Nick\_Groenen](https://forum.ansible.com/u/Nick_Groenen)\
**Post date:** [August 29, 2013, 8:54am UTC](https://forum.ansible.com/t/managing-apt-repository-additions/13379/2 "2013-08-29T08:54:58Z")

</div>

> 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](http://www.ansibleworks.com/docs/playbooks.html).

This is how I deal with these kinds of situations.

---

<div class="post-metadata">

**Author:** ![Mark\_Mandel](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Mark\_Mandel](https://forum.ansible.com/u/Mark_Mandel)\
**Post date:** [August 29, 2013, 10:59pm UTC](https://forum.ansible.com/t/managing-apt-repository-additions/13379/3 "2013-08-29T22:59:27Z")

</div>

Aha! I hadn’t seen that.

Thanks, that will work nicely.

Mark
