为什么我的Ansible任务挂起?

我有以下ansible剧本:

- hosts: node1
  sudo: yes
  gather_facts: no

  tasks:
  - name: update apt
    apt: update_cache=yes
  - name: install python-setuptools
    apt: name=python-setuptools update_cache=yes
  - name: easy_install pexpect module
    easy_install: name=pexpect state=latest
  - name: add geonode repo
    apt_repository: repo='ppa:geonode/stable' state=present
  - name: update apt
    apt: update_cache=yes
  - name: install geonode
    apt: name=geonode update_cache=yes
  - expect:
        command: geonode createsuperuser
        responses:
          (?i)username: 'test'
          (?i)email: 'test@test.com'

当我运行它时,我得到:

PLAY [node1] *******************************************************************

TASK [update apt] **************************************************************
ok: [node1]

TASK [install python-setuptools] ***********************************************
changed: [node1]

TASK [easy_install pexpect module] *********************************************
changed: [node1]

TASK [add geonode repo] ********************************************************
changed: [node1]

TASK [update apt] **************************************************************
ok: [node1]

TASK [install geonode] *********************************************************

然后它无限期地挂起.
在远程节点(node1)中,我检查了dir

/home/vagrant/.ansible/tmp/ansible-tmp-1470059145.13-122191240803512/

在里面运行文件,看看我的任务挂起的原因

vagrant@node1:~/.ansible/tmp/ansible-tmp-1470059145.13-122191240803512$python apt

得到:

{"msg": "Failed to lock apt for exclusive operation", "failed": true, "invocation": {"module_args": {"dpkg_options": "force-confdef,force-confold", "autoremove": false, "force": false, "name": "geonode", "install_recommends": null, "package": ["geonode"], "purge": false, "allow_unauthenticated": false, "state": "present", "upgrade": null, "update_cache": true, "default_release": null, "only_upgrade": false, "deb": null, "cache_valid_time": null}}}

你有什么见解吗?

编辑1:

我整天都在发布这个脚本,但从来没有让它工作过.当我发布这个问题时,很明显,脚本在15分钟内成功执行到最后.我今天午饭之前推出它,1小时后它仍然挂着.为什么我会有这样不同的行为?有没有办法控制它?

最佳答案 此问题可能是由空/ var / lib / apt文件夹引起的.

Vagrant可能需要一段时间来填充这些可能导致apt锁定的文件夹.

此外,由于update_cache被多次使用,因此该剧本效率低下.我建议使用这样的东西:

- hosts: node1
  sudo: yes
  gather_facts: no

  tasks:
    # Pause for 5 minutes to make sure vagrant does not hold apt lock.
    - pause:
        minutes: 5

    - name: add geonode repo
      apt_repository:
        repo: 'ppa:geonode/stable'
        state: present

    - name: Install apt packages.
      apt:
        name: "{{ item }}"
        state: present
        update_cache: true
      with_items:
        - python-setuptools
        - geonode

  - name: Create geonode superuser.
    expect:
      command: geonode createsuperuser
      responses:
        (?i)username: 'test'
        (?i)email: 'test@test.com'        

这样Ansible将不会在播放期间多次更新存储库.

点赞