title: "apt" module in Ansible playbook execution randomly fails on different hosts each time with message "Failed to lock apt for exclusive operation"
body: <p>When i try to install a list of packages('apache2', 'libapache2-mod-wsgi', 'python-pip', 'python-virtualenv') on on a group of hosts (app01 and app02),
  it fails randomly either on app01 or app02.
  After a first few retries the required packages are already installed on the host. Subsequent execution continue to fail randomly on app01 or app02 instead of returning a simple success. </p>
  
  <p>The ansible controller and hosts are all running ubuntu 16.04</p>
  
  <p>The controller has ansible 2.8.4</p>
  
  <p>I have already set "become: yes" in playbook.
  I have already tried running apt-get clean and apt-get update. on the hosts</p>
  
  <p>Inventory file</p>
  
  <pre><code>[webserver]
  app01 ansible_python_interpreter=python3
  app02 ansible_python_interpreter=python3
  
  </code></pre>
  
  <p>Playbook</p>
  
  <pre><code>---
  - hosts: webserver
    tasks:
      - name: install web components
        become: yes
        apt: 
          name: ['apache2', 'libapache2-mod-wsgi', 'python-pip', 'python-virtualenv'] 
          state: present 
          update_cache: yes
  
  </code></pre>
  
  <p>In the first run , the execution fails on host app01</p>
  
  <p>In the second run, the execution fails on host app02</p>
  
  <p>1 st Run</p>
  
  <pre><code>shekhar@control:~/ansible$ ansible-playbook -v playbooks/webservers.yml
  Using /home/shekhar/ansible/ansible.cfg as config file
  
  PLAY [webserver] ******************************************************************************
  
  TASK [Gathering Facts] ******************************************************************************
  ok: [app01]
  ok: [app02]
  
  TASK [install web components] ******************************************************************************
  fatal: [app01]: FAILED! =&gt; {"changed": false, "msg": "Failed to lock apt for exclusive operation"}
  ok: [app02] =&gt; {"cache_update_time": 1568203558, "cache_updated": false, "changed": false}
  
  PLAY RECAP ******************************************************************************
  app01                      : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
  app02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
  </code></pre>
  
  <p>2nd Run</p>
  
  <pre><code>shekhar@control:~/ansible$ ansible-playbook -v playbooks/webservers.yml
  Using /home/shekhar/ansible/ansible.cfg as config file
  
  PLAY [webserver] ******************************************************************************
  
  TASK [Gathering Facts] ******************************************************************************
  ok: [app01]
  ok: [app02]
  
  TASK [install web components] ******************************************************************************
  fatal: [app02]: FAILED! =&gt; {"changed": false, "msg": "Failed to lock apt for exclusive operation"}
  ok: [app01] =&gt; {"cache_update_time": 1568203558, "cache_updated": false, "changed": false}
  
  PLAY RECAP ******************************************************************************
  app01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
  app02                      : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  
  </code></pre>