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
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]
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
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
.