title: Ignore key error on apt-get update from ansible playbook
body: <p>I have a playbook in ansible that install packages from a repository that has invalid keys:</p>
  
  <pre><code>- name: Add Cloudera key
    apt_key:
      keyserver: keys.gnupg.net
      id: F36A89E33CC1BD0F71079007327574EE02A818DD
  
  - name: Install Cloudera packages
    apt:
      name: {{ item }}
      update_cache: yes
      state: latest
      allow_unautenticated: yes
    with_items:
      - sudo
      - libssl-dev
      - ....
  </code></pre>
  
  <p>but ansible fails to update the cache:</p>
  
  <pre><code>"msg": "Failed to update apt cache: W:GPG error: http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease: The following signatures were invalid: F36A89E33CC1BD0F71079007327574EE02A818DD, E:The repository 'http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease' is not signed."
  </code></pre>
  
  <p>even with the <code>allow_unauthenticated</code> option or <code>force</code> option set to yes. How can I update the cache with these key problems?</p>
  
  <p><em>EDIT</em> The <code>apt</code> command that reproduces this behavior are:</p>
  
  <pre><code>sudo wget 'https://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh/cloudera.list' \ -O /etc/apt/sources.list.d/cloudera.list
  sudo apt-get update
  
  
   W: GPG error: http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease: The following signatures were invalid: F36A89E33CC1BD0F71079007327574EE02A818DD
  W: The repository 'http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease' is not signed.
  N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
  N: See apt-secure(8) manpage for repository creation and user configuration details.
  </code></pre>
  
  <p>But I can go on and issue the command</p>
  
  <pre><code>sudo apt-get install hadoop-hdfs-namenode
  </code></pre>
  
  <p>and it installs the package after the warning. Ansible is considering the warning above (<code>W The following signatures were invalid</code>), an error from Cloudera side that provided the wrong key or the wrong signed repository, but moves forward and installs the package:</p>
  
  <pre><code>dpkg -l | grep hadoop-hdfs-namenode
  ii  hadoop-hdfs-namenode                  2.6.0+cdh5.14.2+2748-1.cdh5.14.2.p0.11~jessie-cdh5.14.2 all          Name Node for Hadoop
  </code></pre>
  
  <p>so what I'm trying to achieve is that Ansible reproduces this behavior: execute the <code>apt-get update</code> command and continue without bailing out on the update part. Ansible can install a package from a unsigned repository with the option <code>allow_unauthenticated</code>.</p>
  
  <p><em>EDIT #2</em>: The full ansible command is below:</p>
  
  <pre><code>    iveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/user/.ansible/cp/be00dd5395 -tt 192.168.9.22 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-thnmveqcmiwmvbdbabglejbbsaidohqe; /usr/bin/python /home/user/.ansible/tmp/ansible-tmp-1528224540.4225562-47865757921408/apt.py'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
      Escalation succeeded
      &lt;192.168.9.22&gt; (1, b'\r\n{"msg": "Failed to update apt cache: W:GPG error: http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease: The following signatures were invalid: F36A89E33CC1BD0F71079007327574EE02A818DD, E:The repository \'http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease\' is not signed.", "failed": true, "exception": "  File \\"/tmp/ansible_RDFb3C/ansible_module_apt.py\\", line 991, in main\\n    cache.update()\\n  File \\"/usr/lib/python2.7/dist-packages/apt/cache.py\\", line 464, in update\\n    raise FetchFailedException(e)\\n", "invocation": {"module_args": {"dpkg_options": "force-confdef,force-confold", "upgrade": null, "force": false, "force_apt_get": false, "install_recommends": null, "package": ["sudo", "build-essential", "python-dev", "python3-dev", "openjdk-8-jdk", "git", "libssl-dev", "libsqlite3-dev", "zlib1g-dev", "bzip2", "libreadline-dev", "vim", "rsync", "apt-transport-https", "vsftpd", "ftp", "tmux", "postgresql", "postgresql-client", "libpq-dev", "python-psycopg2", "ntp", "r-base"], "autoclean": false, "name": ["sudo", "build-essential", "python-dev", "python3-dev", "openjdk-8-jdk", "git", "libssl-dev", "libsqlite3-dev", "zlib1g-dev", "bzip2", "libreadline-dev", "vim", "rsync", "apt-transport-https", "vsftpd", "ftp", "tmux", "postgresql", "postgresql-client", "libpq-dev", "python-psycopg2", "ntp", "r-base"], "purge": false, "allow_unauthenticated": true, "state": "latest", "autoremove": false, "update_cache": true, "default_release": null, "only_upgrade": false, "deb": null, "cache_valid_time": 0}}}\r\n', b'Shared connection to 192.168.9.22 closed.\r\n')                                                                                                
      &lt;192.168.9.22&gt; ESTABLISH SSH CONNECTION FOR USER: None
      &lt;192.168.9.22&gt; SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/user/.ansible/cp/be00dd5395 192.168.9.22 '/bin/sh -c '"'"'rm -f -r /home/user/.ansible/tmp/ansible-tmp-1528224540.4225562-47865757921408/ &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'"'"''    
      &lt;192.168.9.22&gt; (0, b'', b'')
      The full traceback is:
        File "/tmp/ansible_RDFb3C/ansible_module_apt.py", line 991, in main
          cache.update()
        File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 464, in update
          raise FetchFailedException(e)
  
      failed: [192.168.9.22] (item=['sudo', 'build-essential', 'python-dev', 'python3-dev', 'openjdk-8-jdk', 'git', 'libssl-dev', 'libsqlite3-dev', 'zlib1g-dev', 'bzip2', 'libreadline-dev', 'vim', 'rsync', 'apt-transport-https', 'vsftpd', 'ftp', 'tmux', 'postgresql', 'postgresql-client', 'libpq-dev', 'python-psycopg2', 'ntp', 'r-base']) =&gt; {               
          "changed": false,
          "invocation": {
              "module_args": {
                  "allow_unauthenticated": true,
                  "autoclean": false,
                  "autoremove": false,
                  "cache_valid_time": 0,
                  "deb": null,
                  "default_release": null,
                  "dpkg_options": "force-confdef,force-confold",
                  "force": false,
                  "force_apt_get": false,
                  "install_recommends": null,
                  "name": [
                      "sudo",
                      "build-essential",
                      "python-dev",
                      "python3-dev",
                      "openjdk-8-jdk",
                      "git",
                      "libssl-dev",
                      "libsqlite3-dev",
                      "zlib1g-dev",
                      "bzip2",
                      "libreadline-dev",
                      "vim",
                      "rsync",
                      "apt-transport-https",
                      "vsftpd",
                      "ftp",
                      "tmux",
                      "postgresql",
                      "postgresql-client",
                      "libpq-dev",
                      "python-psycopg2",
                      "ntp",
                      "r-base"
                  ],
                  "only_upgrade": false,
                  "package": [
                      "sudo",
                      "build-essential",
                      "python-dev",
                      "python3-dev",
                      "openjdk-8-jdk",
                      "git",
                      "libssl-dev",
                      "libsqlite3-dev",
                      "zlib1g-dev",
                      "bzip2",
                      "libreadline-dev",
                      "vim",
                      "rsync",
                      "apt-transport-https",
                      "vsftpd",
                      "ftp",
                      "tmux",
                      "postgresql",
                      "postgresql-client",
                      "libpq-dev",
                      "python-psycopg2",
                      "ntp",
                      "r-base"
                  ],
                  "purge": false,
                  "state": "latest",
                  "update_cache": true,
                  "upgrade": null
              }
          },
          "item": [
              "sudo",
              "build-essential",
              "python-dev",
              "python3-dev",
              "openjdk-8-jdk",
              "git",
              "libssl-dev",
              "libsqlite3-dev",
              "zlib1g-dev",
              "bzip2",
              "libreadline-dev",
              "vim",
              "rsync",
              "apt-transport-https",
              "vsftpd",
              "ftp",
              "tmux",
              "postgresql",
              "postgresql-client",
              "libpq-dev",
              "python-psycopg2",
              "ntp",
              "r-base"
          ],
      "msg": "Failed to update apt cache: W:GPG error: http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease: The following signatures were invalid: F36A89E33CC1BD0F71079007327574EE02A818DD, E:The repository 'http://archive.cloudera.com/cdh5/debian/jessie/amd64/cdh jessie-cdh5 InRelease' is not signed."
  }
  </code></pre>