Repository: ansible/ansible

Issue:
ansible-galaxy: init doesn't create whole scaffolding
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

Ansible Galaxy
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

Ansible 2.1.2.0 upgraded via pip:

```
ansible 2.1.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible']

```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

```
>  cat /etc/ansible/ansible.cfg | grep -v '#' | grep -v '^$'
[defaults]
hostfile       = /etc/ansible/hosts
library        = /usr/share/ansible
remote_tmp     = $HOME/.ansible/tmp
pattern        = *
forks          = 5
poll_interval  = 15
sudo_user      = root
transport      = smart
remote_port    = 22
sudo_exe = sudo
timeout = 10
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
action_plugins     = /usr/share/ansible_plugins/action_plugins
callback_plugins   = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins     = /usr/share/ansible_plugins/lookup_plugins
vars_plugins       = /usr/share/ansible_plugins/vars_plugins
filter_plugins     = /usr/share/ansible_plugins/filter_plugins
[paramiko_connection]
[ssh_connection]
[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 5.0
```
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

```
> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty
> pip --version
pip 8.1.2 from /usr/local/lib/python2.7/dist-packages (python 2.7)
```
##### SUMMARY

"ansible-galaxy init" returns an error and doesn't complete the scaffolding creation.
##### STEPS TO REPRODUCE

```
ansible-galaxy init hardening -vvvv

```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

```

Complete role scaffolding:
README.md
.travis.yml
defaults/
    main.yml
files/
handlers/
    main.yml
meta/
    main.yml
templates/
tests/
    inventory
    test.yml
vars/
    main.yml
```
##### ACTUAL RESULTS

> ansible-galaxy init hardening -vvvv

```
Using /etc/ansible/ansible.cfg as config file
Opened /home/xir/.ansible_galaxy
Initial connection to galaxy_server: https://galaxy.ansible.com
Base API: https://galaxy.ansible.com/api/v1
https://galaxy.ansible.com/api/v1/platforms/?page_size
ERROR! Failed to download the platforms list: name must be a byte string
```

```
 ls -R  hardening
hardening:
README.md  defaults  files  handlers  meta

hardening/defaults:
main.yml

hardening/files:

hardening/handlers:
main.yml

hardening/meta:

```

@gundalow updated the formatting on the above to make the bug report more readable



Discussion:
Looks like the ansible-galaxy api server threw an error when the list of platforms was requested, and that error caused 'ansible-galaxy init' to fail mid creation of the role template. 

One proposed fix: https://github.com/ansible/ansible/pull/18109

(remove the network request that can fail from the 'init' code)


Resolving patch:
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
--- a/lib/ansible/cli/galaxy.py
+++ b/lib/ansible/cli/galaxy.py
@@ -192,18 +192,6 @@ def execute_init(self):
                             "however it will reset any main.yml files that may have\n"
                             "been modified there already." % role_path)
 
-        platforms = []
-        if not offline:
-            platforms = self.api.get_list("platforms") or []
-
-        # group the list of platforms from the api based
-        # on their names, with the release field being
-        # appended to a list of versions
-        platform_groups = defaultdict(list)
-        for platform in platforms:
-            platform_groups[platform['name']].append(platform['release'])
-            platform_groups[platform['name']].sort()
-
         inject_data = dict(
             role_name=role_name,
             author='your name',
@@ -212,7 +200,6 @@ def execute_init(self):
             license='license (GPLv2, CC-BY, etc)',
             issue_tracker_url='http://example.com/issue/tracker',
             min_ansible_version='1.2',
-            platforms=platform_groups,
             container_enabled=self.options.container_enabled
         )
 


Test patch: