apt_repository模块失败了

时间:2016-03-14 15:12:43

标签: java ansible ansible-playbook apt ansible-2.x

有时当我运行我的剧本时,它会抛出下一个失败:

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}

剧本中“有时”失败的部分是下一个:

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

2 个答案:

答案 0 :(得分:0)

在任务之前运行sudo apt-get -y clean && sudo apt-get -y autoclean

答案 1 :(得分:0)

在任何地方使用update_cache: no

ansible 2.5.2,远程主持人: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
    - shell: echo 'mysql-apt-config mysql-apt-config/select-product select Ok' | debconf-set-selections
    - shell: echo 'mysql-apt-config mysql-apt-config/select-tools select Enabled' | debconf-set-selections
    - shell: echo 'mysql-apt-config mysql-apt-config/repo-distro select ubuntu' | debconf-set-selections
    - shell: echo 'mysql-apt-config mysql-apt-config/tools-component string mysql-tools' | debconf-set-selections
    - shell: echo 'mysql-apt-config mysql-apt-config/repo-url string http://repo.mysql.com/apt' | debconf-set-selections
    - 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回来了。