diff options
author | Maxim Masiutin <maxim@masiutin.com> | 2021-05-17 13:09:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 05:09:43 -0500 |
commit | 3aab644285d63af086788b953930634eef46455f (patch) | |
tree | 011a6e11516749cd4587c42e6a6018ba09ba3d44 | |
parent | 3d4d43a1ce336bc672f231a1b3b6ff6235caea66 (diff) | |
download | ansible-3aab644285d63af086788b953930634eef46455f.tar.gz |
The error message about the failure to import a 'gpg' key by the 'ansible.builtin.apt_key' module was incorrect (https://github.com/ansible/ansible/issues/74423) (#74521)
Co-authored-by: Sam Doran <sdoran@redhat.com>
(cherry picked from commit e4d7fc974538f38a0fee3b2a5b304d37e2fc9ab5)
4 files changed, 12 insertions, 2 deletions
diff --git a/changelogs/fragments/74476-apt_key-gpg-inline-data.yaml b/changelogs/fragments/74476-apt_key-gpg-inline-data.yaml new file mode 100644 index 0000000000..e2cb1556ff --- /dev/null +++ b/changelogs/fragments/74476-apt_key-gpg-inline-data.yaml @@ -0,0 +1,2 @@ +bugfixes: + - The error message about the failure to import a ``gpg`` key by the ``apt_key`` module was incorrect (https://github.com/ansible/ansible/issues/74423). diff --git a/lib/ansible/modules/apt_key.py b/lib/ansible/modules/apt_key.py index 87b6410a63..804d0d3ae5 100644 --- a/lib/ansible/modules/apt_key.py +++ b/lib/ansible/modules/apt_key.py @@ -290,7 +290,7 @@ def get_key_id_from_file(module, filename, data=None): (rc, out, err) = module.run_command(cmd, environ_update=lang_env, data=to_native(data)) if rc != 0: - module.fail_json(msg="Unable to extract key from '%s'" % ('inline data' if data is None else filename), stdout=out, stderr=err) + module.fail_json(msg="Unable to extract key from '%s'" % ('inline data' if data is not None else filename), stdout=out, stderr=err) keys = parse_output_for_keys(out) # assume we only want first key? diff --git a/test/integration/targets/apt_key/tasks/apt_key_inline_data.yml b/test/integration/targets/apt_key/tasks/apt_key_inline_data.yml new file mode 100644 index 0000000000..13174e4849 --- /dev/null +++ b/test/integration/targets/apt_key/tasks/apt_key_inline_data.yml @@ -0,0 +1,5 @@ +- name: "Ensure import of a deliberately corrupted downloaded GnuPG binary key results in an 'inline data' occurence in the message" + apt_key: + url: https://ansible-ci-files.s3.us-east-1.amazonaws.com/test/integration/targets/apt_key/apt-key-corrupt-zeros-2k.gpg + register: gpg_inline_result + failed_when: "not ('inline data' in gpg_inline_result.msg)" diff --git a/test/integration/targets/apt_key/tasks/main.yml b/test/integration/targets/apt_key/tasks/main.yml index acafd3edda..9c571f4355 100644 --- a/test/integration/targets/apt_key/tasks/main.yml +++ b/test/integration/targets/apt_key/tasks/main.yml @@ -26,6 +26,9 @@ - import_tasks: 'apt_key.yml' when: ansible_distribution in ('Ubuntu', 'Debian') - + +- import_tasks: 'apt_key_inline_data.yml' + when: ansible_distribution in ('Ubuntu', 'Debian') + - import_tasks: 'file.yml' when: ansible_distribution in ('Ubuntu', 'Debian') |