2
votes

I am configuring a mesos-marathon cluster. I have the next role to install java and mesos.

---
- name: importar key Mesosphere
  shell: gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E56151BF

- name: ppa java8
  apt_repository: repo='ppa:webupd8team/java' state=present

- name: seleccionar licencia Oracle
  shell: echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections

- name: actualizar
  apt: update_cache=yes

- name: instalar java8
  apt: name=oracle-java8-installer state=latest update-cache=yes force=yes

- name: actualizar sources list
  shell: DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]') && CODENAME=$(lsb_release -cs) && echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | sudo tee /etc/apt/sources.list.d/mesosphere.list

- name: actualizar paquetes
  apt: update_cache=yes cache_valid_time=3600

- name: instalar mesos
  apt: name=mesos state=present install_recommends=yes force=yes

- name: instalar mesosphere
  apt: name=mesosphere state=present install_recommends=yes force=yes

My problem is that when I execute the playbook, it gives me the next error:

TASK [common : actualizar sources list] ****************************************
changed: [172.16.8.191]

TASK [common : actualizar paquetes] ********************************************
ok: [172.16.8.191]

TASK [common : instalar mesos] *************************************************
fatal: [172.16.8.191]: FAILED! => {"changed": false, "failed": true, "msg": "No package matching 'mesos' is available"}

PLAY RECAP *********************************************************************
172.16.8.191               : ok=8    changed=5    unreachable=0    failed=1

Ansible error

But if I execute ansible for a second time it works perfectly you can see executing a second time:

TASK [common : actualizar paquetes] ********************************************
ok: [172.16.8.191]

TASK [common : instalar mesos] *************************************************
changed: [172.16.8.191]

TASK [common : instalar mesosphere] ********************************************
changed: [172.16.8.191]

Ansible works

What could be the problem?

Thanks.

SOLUTION BY @ydaetskcoR

Change the task 'instalar mesos':

- name: instalar mesos
  apt: name=mesos state=present install_recommends=yes update_cache=yes force=yes
1
What happens if you add update_cache=yes to the task that installs mesos?ydaetskcoR
Really thanks @ydaetskcoR now it works perfectly, can I know why I have to put the update_cache in the same task as install mesos? and please you can answer the question with your comment.ThanksAsier Gomez

1 Answers

3
votes

The issue you have is that the actualizar paquetes task is only doing an apt-get update to refresh your repo lists if the last update was more than an hour ago.

Considering you've only just added the Mesos repo in the previous task you won't then be able to find the package. Re-running the playbook triggers the actualizar task before that which doesn't have a cache_valid_time setting and so will force an apt-get update which will then allow you to use the Mesos repo that you added in the last playbook run.

To fix it you could just remove the cache_valid_time from the actualizar paquetes task.

As mentioned in the comments, you can also move the update_cache only apt tasks into the main apt task that actually installs packages and Ansible will run the apt-get update before the apt-get install.