# Problem with apt add-repository and updating the cache ?

**URL:** <https://forum.ansible.com/t/problem-with-apt-add-repository-and-updating-the-cache/14791>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [March 17, 2014, 12:06am UTC](https://forum.ansible.com/t/problem-with-apt-add-repository-and-updating-the-cache/14791 "2014-03-17T00:06:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Turner](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Ben\_Turner](https://forum.ansible.com/u/Ben_Turner)\
**Post date:** [March 17, 2014, 12:06am UTC](https://forum.ansible.com/t/problem-with-apt-add-repository-and-updating-the-cache/14791/1 "2014-03-17T00:06:48Z")

</div>

I’m running Ansible 1.5.3 on Ubuntu 12.04 LTS

I’ve got the following two lines in one of my roles:

- name: Add brightbox repository  
apt\_repository: repo=ppa:brightbox/ruby-ng

- name: Install brightbox ruby  
apt: pkg=ruby1.9.3 state=latest

This outputs the following (Note: abbreviated. Full error log shown below):

failed: [[ec2-54-253-255-54.ap-southeast-2.compute.amazonaws.com](http://ec2-54-253-255-54.ap-southeast-2.compute.amazonaws.com)] =\> (item=ruby1.9.3) =\> {“failed”: true, “item”: “ruby1.9.3”}  
stderr: E: There are problems and -y was used without --force-yes

…  
WARNING: The following packages cannot be authenticated!  
libruby1.9.1 ruby1.9.1 ri1.9.1 ruby1.9.1-dev ruby1.9.1-examples  
libruby1.9.1-dbg ruby1.9.1-full ruby1.9.3

This, I believe, is usually a sign that “apt-get update” has not been run - indeed going onto the box, manually running apt-get update, and then rerunning my playbook causes it to install successfully.

Thinking it might be a bug in the apt\_repository code or documentation, I bought up a new copy of the server and changed the apt\_respository to include the (default) value of true for the update\_cache attribute:

- name: Add brightbox repository  
apt\_repository: repo=ppa:brightbox/ruby-ng update\_cache=yes

This made no difference. But when I added update\_cache to the apt command instead, it now worked:

- name: Install brightbox ruby  
apt: pkg=ruby1.9.3 state=latest update\_cache=yes

So I’m a little puzzled as to why the apt\_repository command doesn’t update the apt index in time to fix the following install task, but the apt take does manage to update the index in time ?  
Obviously, I’d rather not update my apt index before every run on the apt module, and logically the only reason I am updating it is for the new repository I’ve added, so would prefer the apt\_repository task to own that responsibility.

Regards,  
Ben

FULL ERROR TRACE

---

<div class="post-metadata">

**Author:** ![Ben\_Turner](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Ben\_Turner](https://forum.ansible.com/u/Ben_Turner)\
**Post date:** [March 17, 2014, 12:41am UTC](https://forum.ansible.com/t/problem-with-apt-add-repository-and-updating-the-cache/14791/2 "2014-03-17T00:41:54Z")

</div>

Addenda:

It seems I had to ALSO add in the key manually, as the apt\_repository command had not done that for me - this isn’t what I’d expected from a PPA ?

- name: Add brightbox repository key  
apt\_key: url=“[http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0xF5DA5F09C3173AA6](http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0xF5DA5F09C3173AA6)”

This was required, along with the apt update\_cache command. Still puzzled why.

Regards,  
Ben

---

<div class="post-metadata">

**Author:** ![Ben\_Turner](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Ben\_Turner](https://forum.ansible.com/u/Ben_Turner)\
**Post date:** [March 17, 2014, 5:48am UTC](https://forum.ansible.com/t/problem-with-apt-add-repository-and-updating-the-cache/14791/3 "2014-03-17T05:48:17Z")

</div>

This also happened when running an external role (from Ansible Galaxy)

I had to uncomment line 7 of [https://github.com/bcoca/oracle7java/blob/54d5fd3a56d6b2d4186c5c8fabb24b6f42a1f731/tasks/main.yml](https://github.com/bcoca/oracle7java/blob/54d5fd3a56d6b2d4186c5c8fabb24b6f42a1f731/tasks/main.yml) to ensure the apt-key was also installed, as the previous apt-repository command didn’t do so.

This would appear to be a regression in 1.5.3 at this stage ?

Ben
