<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">apt_key</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.0.0
  config file = None
  configured module search path = [u'/home/mg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mg/.venv/local/lib/python2.7/site-packages/ansible
  executable location = /home/mg/.venv/bin/ansible
  python version = 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]"><pre class="notranslate"><code class="notranslate">ansible 2.4.0.0
  config file = None
  configured module search path = [u'/home/mg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mg/.venv/local/lib/python2.7/site-packages/ansible
  executable location = /home/mg/.venv/bin/ansible
  python version = 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubuntu</p>
<h5 dir="auto">SUMMARY</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible &lt;hostname&gt; -m apt_key -a url=https://downloads.linux.hpe.com/SDR/hpePublicKey2048_key1.pub --check"><pre class="notranslate"><code class="notranslate">ansible &lt;hostname&gt; -m apt_key -a url=https://downloads.linux.hpe.com/SDR/hpePublicKey2048_key1.pub --check
</code></pre></div>
<p dir="auto">goes ahead and adds the apt key, ignoring the <code class="notranslate">--check</code> mode.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">See above.</p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">No key is added; status is "changed".</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Key is added; status is "changed".</p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/selivan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/selivan">@selivan</a> on 2016-06-15T16:15:11Z</p>

<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">apt_key</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto"><code class="notranslate">ansible --version</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Management host: Ubuntu 14.04 Trusty<br>
Controlled host: Ubuntu 14.04 Trusty</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">If apt_key module takes keyfile from <code class="notranslate">data="{{ lookup('file', 'key.gpg') }}"</code>, it always marks task as "changed" in <code class="notranslate">--check</code> mode, despite that this key is present in apt keyring on target host. In normal mode is marks this task as "ok".</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto"><code class="notranslate">roles/common-monitoring/tasks/main.yml</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: add zabbix repository apt key
  apt_key: data=&quot;{{ lookup('file', 'zabbix-official-repo.key') }}&quot; state=present"><pre class="notranslate"><code class="notranslate">- name: add zabbix repository apt key
  apt_key: data="{{ lookup('file', 'zabbix-official-repo.key') }}" state=present
</code></pre></div>
<p dir="auto"><code class="notranslate">roles/common-monitoring/files/zabbix-official-repo.key</code> : <a href="https://gist.github.com/selivan/44d970b55b75a6435d02f2b42dbe44db">https://gist.github.com/selivan/44d970b55b75a6435d02f2b42dbe44db</a></p>
<p dir="auto"><code class="notranslate">playbook.yml</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: remote_host
  become: yes
  roles:
    - { role: common-monitoring, tags: ['common-monitoring'] }
"><pre class="notranslate"><code class="notranslate">- hosts: remote_host
  become: yes
  roles:
    - { role: common-monitoring, tags: ['common-monitoring'] }

</code></pre></div>
<p dir="auto"><code class="notranslate">ansible-playbook playbook.yml --check</code></p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Task should be reported as "ok" because key already exists in apt keyring on remote host.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Task is always reported as "changed".</p>
<p dir="auto"><code class="notranslate">ansible-playbook playbook.yml --check -vvv</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [common-monitoring : add zabbix repository apt key] ***********************
task path: /home/XXXXXX/ansible/roles/common-monitoring/tasks/main.yml:3
File lookup using /home/XXXXXX/ansible/roles/common-monitoring/files/zabbix-official-repo.key as file
&lt;XX.XX.XX.XX&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;XX.XX.XX.XX&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=g
ssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/XXXXXX/.ansible/cp/ansib
le-ssh-%h-%p-%r 172.31.113.12 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391 `&quot; &amp;&amp; e
cho ansible-tmp-1466006828.99-150895880810391=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;XX.XX.XX.XX&gt; PUT /tmp/tmpSGoEiZ TO /home/XXXXXX/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391/apt_key
&lt;XX.XX.XX.XX&gt; SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthenticat
ions=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/XXXXXX/.ansible/cp
/ansible-ssh-%h-%p-%r '[172.31.113.12]'
&lt;XX.XX.XX.XX&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;XX.XX.XX.XX&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=g
ssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/XXXXXX/.ansible/cp/ansib
le-ssh-%h-%p-%r -tt 172.31.113.12 '/bin/sh -c '&quot;'&quot;'sudo -H -S -n -u root /bin/sh -c '&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'echo BECOME-SUCCESS-rstyhbjupbasyihpfmmshmtlc
qyjhfhu; LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/XXXXXX/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391/apt_key; rm -rf &quot;/ho
me/XXXXXX/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;' &amp;&amp; sleep 0'&quot;'&quot;''
changed: [log01] =&gt; {&quot;changed&quot;: true, &quot;invocation&quot;: {&quot;module_args&quot;: {&quot;data&quot;: &quot;-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1.4.5 (GNU/Lin
ux)\n\nmQGiBFCNJaYRBAC4nIW8o2NyOIswb82Xn3AYSMUc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9m7avQxguMqufgg\nfAk7377Rt9RqiEkEGBECAAkFAlCNJaYCGwwACgk
Q0T1Y5HnqXtQx4wCfcJZINKVq\nkQIoV3KTQAIzr6IvbZoAn12XXt4GP89xHuzPDZ86YJVAgnfK\n=+200\n-----END PGP PUBLIC KEY BLOCK-----&quot;, &quot;file&quot;: null, &quot;id&quot;: null,
 &quot;key&quot;: null, &quot;keyring&quot;: null, &quot;keyserver&quot;: null, &quot;state&quot;: &quot;present&quot;, &quot;url&quot;: null, &quot;validate_certs&quot;: true}, &quot;module_name&quot;: &quot;apt_key&quot;}}"><pre class="notranslate"><code class="notranslate">TASK [common-monitoring : add zabbix repository apt key] ***********************
task path: /home/XXXXXX/ansible/roles/common-monitoring/tasks/main.yml:3
File lookup using /home/XXXXXX/ansible/roles/common-monitoring/files/zabbix-official-repo.key as file
&lt;XX.XX.XX.XX&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;XX.XX.XX.XX&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=g
ssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/XXXXXX/.ansible/cp/ansib
le-ssh-%h-%p-%r 172.31.113.12 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391 `" &amp;&amp; e
cho ansible-tmp-1466006828.99-150895880810391="` echo $HOME/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391 `" ) &amp;&amp; sleep 0'"'"''
&lt;XX.XX.XX.XX&gt; PUT /tmp/tmpSGoEiZ TO /home/XXXXXX/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391/apt_key
&lt;XX.XX.XX.XX&gt; SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthenticat
ions=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/XXXXXX/.ansible/cp
/ansible-ssh-%h-%p-%r '[172.31.113.12]'
&lt;XX.XX.XX.XX&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;XX.XX.XX.XX&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=g
ssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/XXXXXX/.ansible/cp/ansib
le-ssh-%h-%p-%r -tt 172.31.113.12 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-rstyhbjupbasyihpfmmshmtlc
qyjhfhu; LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/XXXXXX/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391/apt_key; rm -rf "/ho
me/XXXXXX/.ansible/tmp/ansible-tmp-1466006828.99-150895880810391/" &gt; /dev/null 2&gt;&amp;1'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
changed: [log01] =&gt; {"changed": true, "invocation": {"module_args": {"data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1.4.5 (GNU/Lin
ux)\n\nmQGiBFCNJaYRBAC4nIW8o2NyOIswb82Xn3AYSMUcNZuKB2fMtpu0WxSXIRiX2BwC\nYXx8cIEQVYtLRBL5o0JdmoNCjW6jd5fOVem3EmOcPksvzzRWonIgFHf4EI2n1KJc\nJXX/nDC
+eoh5xW35mRNFN/BEJHxxiRGGbp2MCnApwgrZLhOujaCGAwavGwCgiG4D\nwKMZ4xX6Y2Gv3MSuzMIT0bcEAKYn3WohS+udp0yC3FHDj+oxfuHpklu1xuI3y6ha\n402aEFahNi3wr316ukgdP
AYLbpz76ivoouTJ/U2MqbNLjAspDvlnHXXyqPM5GC6K\njtXPqNrRMUCrwisoAhorGUg/+S5pyXwsWcJ6EKmA80pR9HO+TbsELE5bGe/oc238\nt/2oBAC3zcQ46wPvXpMCNFb+ED71qDOlnDY
aaAPbjgkvnp+WN6nZFFyevjx180Kw\nqWOLnlNP6JOuFW27MP75MDPDpbAAOVENp6qnuW9dxXTN80YpPLKUxrQS8vWPnzkY\nWtUfF75pEOACFVTgXIqEgW0E6oww2HJi9zF5fS8IlFHJztNYt
bQgWmFiYml4IFNJ\nQSA8cGFja2FnZXJAemFiYml4LmNvbT6IYAQTEQIAIAUCUI0lpgIbAwYLCQgHAwIE\nFQIIAwQWAgMBAh4BAheAAAoJENE9WOR56l7UhUwAmgIGZ39U6D2w2oIWDD8m7KV
3\noI06AJ9EnOxMMlxEjTkt9lEvGhEX1bEh7bkBDQRQjSWmEAQAqx+ecOzBbhqMq5hU\nl39cJ6l4aocz6EZ9mSSoF/g+HFz6WYnPAfRaYyfLmZdtF5rGBDD4ysalYG5yD59R\nMv5tNVf/CEx
+JAPMhp6JCBkGRaH+xHws4eBPGkea4rGNVP3L3rA7g+c1YXZICGRI\nOOH7CIzIZ/w6aFGsPp7xM35ogncAAwUD/3s8Nc1OLDy81DC6rGpxfEURd5pvd/j0\nD5Di0WSBEcHXp5nThDz6ro/Vr
0/FVIBtT97tmBHX27yBS3PqxxNRIjZ0GSWQqdws\nQ8o3YT+RHjBugXn8CzTOvIn+2QNMA8EtGIZPpCblJv8q6MFPi9m7avQxguMqufgg\nfAk7377Rt9RqiEkEGBECAAkFAlCNJaYCGwwACgk
Q0T1Y5HnqXtQx4wCfcJZINKVq\nkQIoV3KTQAIzr6IvbZoAn12XXt4GP89xHuzPDZ86YJVAgnfK\n=+200\n-----END PGP PUBLIC KEY BLOCK-----", "file": null, "id": null,
 "key": null, "keyring": null, "keyserver": null, "state": "present", "url": null, "validate_certs": true}, "module_name": "apt_key"}}
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="160463302" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/3958" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/3958/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/3958">ansible/ansible-modules-core#3958</a></p>