Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The error message about the failure to import a 'gpg' key by the 'ansible.builtin.apt_key' module was incorrect #74476

Merged
merged 1 commit into from Apr 30, 2021

Conversation

maximmasiutin
Copy link
Contributor

@maximmasiutin maximmasiutin commented Apr 28, 2021

SUMMARY

When importing a key by the apt_key module, in case of error, the error message was incorrect, because the logic to distinguish between the file name and the explicit data was inversed.

The error message was:

Unable to extract key from '-'

While it should have been:

Unable to extract key from 'inline data'

The relevant code is in the following line from: /lib/ansible/modules/apt_key.py

module.fail_json(msg="Unable to extract key from '%s'" % ('inline data' if data is None else filename), stdout=out, stderr=err)

(it should have been if data is None)

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/modules/apt_key

ADDITIONAL INFORMATION

Fixes: #74423

To reproduce this error, create the following files:

The Vagrantfile file:

Vagrant.configure("2") do |config|
  config.vm.base_mac = nil
  config.vm.synced_folder ".", "/vagrant", disabled: false

  config.vm.define "test-host" do |n|
    n.vm.box = "ubuntu/bionic64"
    n.vm.hostname = "test-host"
    n.vm.provision :ansible do |ansible|
      ansible.limit = "all"
      ansible.playbook = "test.yaml"
    end
  end
end

The test.yaml file:

- name: Test Playbook
  hosts: test-host
  become: yes
  tasks:
    - name: Add binary key
      apt_key: url=https://packages.cloud.google.com/apt/doc/apt-key.gpg

and run vagrant up

Expected Results:

Unable to extract key from 'inline data'

Actual Results:

Unable to extract key from '-'

@Akasurde - please review

@ansibot ansibot added affects_2.12 module This issue/PR relates to a module. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 28, 2021
@maximmasiutin
Copy link
Contributor Author

ready_for_review

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. has_issue and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 28, 2021
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Apr 29, 2021
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Apr 29, 2021
Copy link
Contributor

@samdoran samdoran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the binary file apt-key-corrupt-zeros-2k.gpg.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. bug This issue/PR relates to a bug. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Apr 29, 2021
…ible.builtin.apt_key' module was incorrect (ansible#74423)

Co-authored-by: Sam Doran <sdoran@redhat.com>
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. labels Apr 30, 2021
@maximmasiutin
Copy link
Contributor Author

maximmasiutin commented Apr 30, 2021

@samdoran I have removed the binary file apt-key-corrupt-zeros-2k.gpg and resolved all your observation.

@maximmasiutin
Copy link
Contributor Author

ready_for_review

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 30, 2021
@samdoran samdoran merged commit 6ea81b8 into ansible:devel Apr 30, 2021
@samdoran
Copy link
Contributor

Please create a backport PR against stable-2.10 and stable-2.11.

@maximmasiutin
Copy link
Contributor Author

Thank you for accepting the request! I will create a backport as @samdoran suggested.

@maximmasiutin
Copy link
Contributor Author

I have created a backport at #74521

@ansible ansible locked and limited conversation to collaborators May 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.12 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid error message on GnuPG key import error in the apt_key module
4 participants