Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apt_repository module fails ansible

sometimes when I run my playbook it throws the next fail:

FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1457967885.72-104659711487416/apt_repository\", 
line 3210, in <module>\r\n    main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1457967885.72-104659711487416/apt_repository\", line 469, in main\r\n`    `cache.update()\r\n  File \"/usr/lib/python2.7/dist-packages/apt/cache.py\", line 440, 
in update\r\n    raise FetchFailedException(e)\r\napt.cache.FetchFailedException: W:Imposible obtener` `http://security.ubuntu.com/ubuntu/dists/trusty-security/main/source/Sources`  `La suma hash difiere\r\n, 
W:Imposible obtener http://security.ubuntu.com/ubuntu/dists/trusty-security/main/binary-amd64/Packages  La suma hash difiere\r\n, W:Imposible obtener http://security.ubuntu.com/ubuntu/dists/trusty-security/main/binary-i386/Packages  La suma hash difiere\r\n, 
E:Algunos archivos de` `índice fallaron al descargar. Se han ignorado, o se han utilizado unos` `antiguos en su lugar\r\n", 
"msg": "MODULE FAILURE", "parsed": false}

the part of the playbook that 'sometimes' fails, is the next:

- name: ppa java8
  apt_repository: repo=ppa:webupd8team/java state=present update_cache=yes
like image 344
Asier Gomez Avatar asked Mar 14 '16 15:03

Asier Gomez


2 Answers

v1. Use update_cache: no everywhere.

ansible 2.5.2, remote host: ubuntu 18.04

- name: Install MySQL utilities and workbench 4 Ubuntu
  when:
    - ansible_distribution == 'Ubuntu'
    - ansible_architecture == 'x86_64'
  become: yes
  block:
    - apt:
        update_cache: no
    - apt_repository:
        repo: deb http://repo.mysql.com/apt/ubuntu/ {{ ansible_distribution_release }} mysql-apt-config
        state: present
        filename: mysql
        update_cache: no
    - apt_repository:
        repo: deb http://repo.mysql.com/apt/ubuntu/ {{ ansible_distribution_release }} mysql-tools
        state: present
        filename: mysql
        update_cache: no
    - apt_key:
        # url: http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x8C718D3B5072E1F5
        keyserver: pool.sks-keyservers.net
        id: 8C718D3B5072E1F5
        state: present
    - debconf:
        name: mysql-apt-config
        question: select-product
        vtype: select
        value: Ok
    - debconf:
        name: mysql-apt-config
        question: select-tools
        vtype: select
        value: Enabled
    - debconf:
        name: mysql-apt-config
        question: repo-distro
        vtype: select
        value: ubuntu
    - debconf:
        name: mysql-apt-config
        question: tools-component
        vtype: select
        value: mysql-tools
    - debconf:
        name: mysql-apt-config
        question: repo-url
        vtype: select
        value: http://repo.mysql.com/apt
    - debconf:
        name: mysql-apt-config
        question: select-server
        vtype: select
        value: mysql-{{ mysql_version }}
    - apt:
        update_cache: yes
    - apt:
        name: "{{ item }}"
        state: latest
        install_recommends: yes
        force: yes
      with_items:
        - mysql-apt-config
        - mysql-utilities
        - mysql-workbench

- name: Install MySQL CLI 4 Ubuntu
  when:
    - ansible_distribution == 'Ubuntu'
    - ansible_architecture == 'x86_64'
  become: yes
  block:
    - apt:
        update_cache: no
    - apt_repository:
        repo: deb https://packagecloud.io/amjith/mycli/ubuntu/ {{ ansible_distribution_release }} main
        filename: amjith_mycli
        update_cache: no
    - apt_key:
        url: https://packagecloud.io/amjith/mycli/gpgkey
        state: present
    - apt:
        update_cache: yes
    - apt:
        name: mycli
        state: latest

Bug is back.

v2. Add a new key first (UPD 20-10-2020).

- apt_key:
    # url: http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x8C718D3B5072E1F5
    keyserver: pool.sks-keyservers.net
    id: 8C718D3B5072E1F5
    state: present
- apt_repository:
    repo: deb http://repo.mysql.com/apt/ubuntu/ {{ ansible_distribution_release }} mysql-apt-config
    state: present
    filename: mysql
- apt_repository:
    repo: deb http://repo.mysql.com/apt/ubuntu/ {{ ansible_distribution_release }} mysql-tools
    state: present
    filename: mysql
like image 165
don Rumata Avatar answered Nov 09 '22 18:11

don Rumata


run sudo apt-get -y clean && sudo apt-get -y autoclean before your task.

like image 2
ffghfgh Avatar answered Nov 09 '22 18:11

ffghfgh