Repository: ansible/ansible

Issue:
zypper_repository: Fails to import GPG keys when 'name' parameter is missing
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
zypper_repository module

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/mchandras/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC]
```

However, this also affects the stable 2.3 release too

##### CONFIGURATION

##### OS / ENVIRONMENT
openSUSE Tumbleweed

##### SUMMARY
When using the `auto_import_keys` parameter in the zypper_repository module, the keys are not imported if the `name` parameter is not set

##### STEPS TO REPRODUCE
Use this playbook

```yaml
- name: foobar                                                                                                                                                                                
  hosts: localhost                                                                                                                                                                            
  become: yes                                                                                                                                                                                 
  tasks:                                                                                                                                                                                      
    - name: Add repo                                                                                                                                                                          
      zypper_repository:                                                                                                                                                                      
        repo: " https://download.opensuse.org/repositories/home:/markoschandras:/sysinstall/openSUSE_Tumbleweed/home:markoschandras:sysinstall.repo"                                                    
        auto_import_keys: yes  
```

##### EXPECTED RESULTS
They gpg key should have been imported

##### ACTUAL RESULTS
Once you add the repository from the 'Configuration' step, try to install 'ipxe'

```
$ sudo zypper in ipxe
Retrieving repository 'home:markoschandras:sysinstall (openSUSE_Tumbleweed)' metadata -----------------------------------------------------------------------------------------------------[\]

New repository or package signing key received:

  Repository:       home:markoschandras:sysinstall (openSUSE_Tumbleweed)                    
  Key Name:         home:markoschandras OBS Project <home:markoschandras@build.opensuse.org>
  Key Fingerprint:  D8E86E1C 3DA78D44 93FDB218 7307D1F1 F0CC0B26                            
  Key Created:      Wed 09 Dec 2015 16:29:25 GMT                                            
  Key Expires:      Fri 16 Feb 2018 16:29:25 GMT                                            
  Rpm Name:         gpg-pubkey-f0cc0b26-566856e5                                            


Do you want to reject the key, trust temporarily, or trust always? [r/t/a/? shows all options] (r): 
```
That should not happen. We use the `auto_import_keys` option so they key should have been imported. However, if you use the following playbook, then everything works.

```yaml
- name: foobar                                                                                                                                                                                
  hosts: localhost                                                                                                                                                                            
  become: yes                                                                                                                                                                                 
  tasks:                                                                                                                                                                                      
    - name: Add repo                                                                                                                                                                          
      zypper_repository:                                                                                                                                                                      
        name: "ipxe"                                                                                                                                                                          
        repo: "https://download.opensuse.org/repositories/home:/markoschandras:/sysinstall/openSUSE_Tumbleweed/"                                                                              
        auto_import_keys: yes
```

The docs do not mention that we need to use the `name` parameter for `auto_import_keys` to work and I don't think that's strictly required anyway.


Discussion:
cc @matze @robinro
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
The general issue is that the resulting name or URL of .repo files is unknown without actually downloading and parsing that file.

Because of that, I find the workaround to require a `name` acceptable. The documentation should be improved to reflect that. Feel free to open a PR.

I'm also open for a proper fix, but I don't see a solution without downloading the .repo file and parsing it. Doing so would be acceptable in my view, but requires a sizeable amount of work and testing.

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/zypper_repository.py b/lib/ansible/modules/packaging/os/zypper_repository.py
--- a/lib/ansible/modules/packaging/os/zypper_repository.py
+++ b/lib/ansible/modules/packaging/os/zypper_repository.py
@@ -81,6 +81,7 @@
             - Automatically import the gpg signing key of the new or changed repository.
             - Has an effect only if state is I(present). Has no effect on existing (unchanged) repositories or in combination with I(absent).
             - Implies runrefresh.
+            - Only works with C(.repo) files if `name` is given explicitly.
         required: false
         default: "no"
         choices: ["yes", "no"]


Test patch: