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

Invalid error message on GnuPG key import error in the apt_key module #74423

Closed
1 task done
maximmasiutin opened this issue Apr 26, 2021 · 1 comment · Fixed by #74476
Closed
1 task done

Invalid error message on GnuPG key import error in the apt_key module #74423

maximmasiutin opened this issue Apr 26, 2021 · 1 comment · Fixed by #74476
Labels
affects_2.12 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@maximmasiutin
Copy link
Contributor

maximmasiutin commented Apr 26, 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

Bug Report

Component Name

ansible.builtin.apt_key module

Ansible Version

2.12.0.dev0 (latest revision from GitHub)
2.11.0rc2 (from pip install ansible)

Configuration

config not changed

OS / Environment

Ubuntu 18

Steps to Reproduce

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 '-'

Relevant file:
lib/ansible/modules/apt_key.py

@jvantuyl - please review
@Akasurde - please review

Fixed by #74476

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2021

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.12 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 26, 2021
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 26, 2021
…e error message was incorrect because of a mixed logic bug - see ansible#74423 ; The command line of GnuPG was logged in some cases but not logged in the other -- now it is logged in all cases; Some exceptions were not logged; Long strings made shorter to avoid pylint warnings; Fixed a pyling warning that the function did not always return a value
@ansibot ansibot added the has_pr This issue has an associated PR. label Apr 26, 2021
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 26, 2021
…e error message was incorrect because of a mixed logic bug - see ansible#74423 ; The command line of GnuPG was logged in some cases but not logged in the other -- now it is logged in all cases; Some exceptions were not logged; Long strings made shorter to avoid pylint warnings; Fixed a pylint warning that the function did not always return a value; Not all GnuPG return codes were analyzed (rc != 0) and logged; Minor pylint issues resolved like (key_id_len != 8 and key_id_len != 16) replaced to (key_id_len not in (8, 16))
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 27, 2021
…e error message was incorrect because of a mixed logic bug - see ansible#74423 ; The command line of GnuPG was logged in some cases but not logged in the other -- now it is logged in all cases; Some exceptions were not logged; Long strings made shorter to avoid pylint warnings; Fixed a pylint warning that the function did not always return a value; Not all GnuPG return codes were analyzed (rc != 0) and logged; Minor pylint issues resolved like (key_id_len != 8 and key_id_len != 16) replaced to (key_id_len not in (8, 16)); Added a test case and a changelog fragment
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 27, 2021
…e error message was incorrect because of a mixed logic bug - see ansible#74423 ; The command line of GnuPG was logged in some cases but not logged in the other -- now it is logged in all cases; Some exceptions were not logged; Long strings made shorter to avoid pylint warnings; Fixed a pylint warning that the function did not always return a value; Not all GnuPG return codes were analyzed (rc != 0) and logged; Minor pylint issues resolved like (key_id_len != 8 and key_id_len != 16) replaced to (key_id_len not in (8, 16)); Added a test case and a changelog fragment
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Apr 27, 2021
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 28, 2021
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 28, 2021
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 30, 2021
…ible.builtin.apt_key' module was incorrect (ansible#74423)

Co-authored-by: Sam Doran <sdoran@redhat.com>
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 30, 2021
…ible.builtin.apt_key' module was incorrect (ansible#74423)

Co-authored-by: Sam Doran <sdoran@redhat.com>
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 30, 2021
…ible.builtin.apt_key' module was incorrect (ansible#74423)

Co-authored-by: Sam Doran <sdoran@redhat.com>

(cherry picked from commit e4d7fc9)
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue Apr 30, 2021
…ible.builtin.apt_key' module was incorrect (ansible#74423)

Co-authored-by: Sam Doran <sdoran@redhat.com>

(cherry picked from commit e4d7fc9)
maximmasiutin added a commit to maximmasiutin/ansible that referenced this issue May 1, 2021
…ible.builtin.apt_key' module was incorrect (ansible#74423)

Co-authored-by: Sam Doran <sdoran@redhat.com>
(cherry picked from commit e4d7fc9)
relrod pushed a commit that referenced this issue May 17, 2021
…ible.builtin.apt_key' module was incorrect (#74423) (#74521)

Co-authored-by: Sam Doran <sdoran@redhat.com>
(cherry picked from commit e4d7fc9)
@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. has_pr This issue has an associated PR. 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
3 participants