Repository: ansible/ansible

Issue:
ansible-galaxy init no longer generating templates directory
##### ISSUE TYPE

 - Bug Report


##### COMPONENT NAME
ansible-galaxy

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible --version
ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.11 (default, Nov  7 2016, 10:40:46) [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]
```

##### CONFIGURATION
Stock configuration

##### OS / ENVIRONMENT
Mac OSX

##### SUMMARY
ansible-galaxy init roleName no longer generates a templates directory by default. 

##### STEPS TO REPRODUCE
1. Create a roles directory inside your project directory
2. Run ansible-galaxy init roleName

##### EXPECTED RESULTS
```
nginx
├── README.md
├── defaults
│   └── main.yml
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml
```
##### ACTUAL RESULTS
```
apache
├── README.md
├── defaults
│   └── main.yml
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── tasks
│   └── main.yml
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml
```
This does not occur against 2.4, but opened an issue to get this fixed against stable. 


Discussion:
So far, I can't reproduce this with 2.3 or devel/2.4:

```
[fedora-25:ansible (v2.3.0.0-1-branch %)]$ ansible --version
ansible 2.3.0.0 (v2.3.0.0-1-branch d56ba0945d) last updated 2017/04/13 12:22:33 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jan 12 2017, 17:59:37) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
[fedora-25:ansible (v2.3.0.0-1-branch %)]$ ansible-galaxy init -p /tmp/testrole/ foobar2
- foobar2 was created successfully
[fedora-25:ansible (v2.3.0.0-1-branch %)]$ ls /tmp/testrole/foobar2
defaults  files  handlers  meta  README.md  tasks  templates  tests  vars
[fedora-25:ansible (v2.3.0.0-1-branch %)]$ ls /tmp/testrole/foobar2/templates/
```

The reason why you could not re-produce is because you've tried it in Linux.

I have the same problem. In OS X, ansible-galaxy init doesn't make the 'files' and 'templates' directory. Definitely a bug. This was the case since I upgraded to 2.3. Here is the output from my terminal.

```
PC-7270L:roles vseneviratne$ ansible --version
ansible 2.3.0.0
  config file = /Users/vseneviratne/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
```
Works for me on OSX as well, 2.3.0.0-1 and devel/

```
11:28 $ rm -rf foobar*
✔ /tmp/testrole 
11:28 $ ansible --version
ansible 2.3.0.0 (v2.3.0.0-1-branch d56ba0945d) last updated 2017/04/21 11:26:24 (GMT -400)
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Oct 11 2016, 05:16:02) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
✔ /tmp/testrole 
11:28 $ uname -a
Darwin mbp.g.a 14.5.0 Darwin Kernel Version 14.5.0: Fri Feb 17 10:33:20 PST 2017; root:xnu-2782.50.9.1.1~1/RELEASE_X86_64 x86_64
✔ /tmp/testrole 
11:28 $ ls -al
total 0
drwxr-xr-x   2 adrian  wheel   68 Apr 21 11:28 .
drwxrwxrwt  11 root    wheel  374 Apr 21 11:26 ..
✔ /tmp/testrole 
11:28 $ ansible-galaxy init  foobar11
- foobar11 was created successfully
✔ /tmp/testrole 
11:29 $ ls -R foobar11
README.md defaults  files     handlers  meta      tasks     templates tests     vars

foobar11/defaults:
main.yml

foobar11/files:

foobar11/handlers:
main.yml

foobar11/meta:
main.yml

foobar11/tasks:
main.yml

foobar11/templates:

foobar11/tests:
inventory test.yml

foobar11/vars:
main.yml
```


@michelleperz @universalvishwa  what was the exact command line used?

@universalvishwa In /Users/vseneviratne/.ansible.cfg,  what are the values (if set) for:
* defaults 
  * roles_path
* galaxy
   * role_skeleton
   * role_skeleton_ignore

Do the roles dirs already exist or are they new?
@michelleperz @universalvishwa   how was ansible installed?

In the installed version of ansible what are the contents (la -laR) of the dir
 $THE_PATH_TO_THE_ANSIBLE_INSTALL/lib/ansible/galaxy

Hi,

Here is the info requested....
```

vseneviratne$ cat /Users/vseneviratne/.ansible.cfg
[defaults]
host_key_checking = False
```

```
sh-3.2# pwd
/Library/Python/2.7/site-packages/ansible/galaxy
sh-3.2# ls -laR
total 168
drwxr-xr-x  13 root  wheel    442 Feb 21 15:06 .
drwxr-xr-x  23 root  wheel    782 Feb 21 15:06 ..
-rw-r--r--   1 root  wheel   3042 Jan 16 09:48 __init__.py
-rw-r--r--   1 root  wheel   3169 Feb 21 15:06 __init__.pyc
-rw-r--r--   1 root  wheel  10574 Jan 16 09:48 api.py
-rw-r--r--   1 root  wheel  10491 Feb 21 15:06 api.pyc
drwxr-xr-x   6 root  wheel    204 Feb 21 15:06 data
-rw-r--r--   1 root  wheel   4535 Jan 16 09:48 login.py
-rw-r--r--   1 root  wheel   4209 Feb 21 15:06 login.pyc
-rw-r--r--   1 root  wheel  13346 Jan 16 09:48 role.py
-rw-r--r--   1 root  wheel   9683 Feb 21 15:06 role.pyc
-rw-r--r--   1 root  wheel   2167 Jan 16 09:48 token.py
-rw-r--r--   1 root  wheel   2371 Feb 21 15:06 token.pyc

./data:
total 32
drwxr-xr-x   6 root  wheel   204 Feb 21 15:06 .
drwxr-xr-x  13 root  wheel   442 Feb 21 15:06 ..
-rw-r--r--   1 root  wheel  1871 Jan 16 09:48 metadata_template.j2
-rw-r--r--   1 root  wheel  1328 Jan 16 09:48 readme
-rw-r--r--   1 root  wheel    73 Jan 16 09:48 test_playbook.j2
-rw-r--r--   1 root  wheel   539 Jan 16 09:48 travis.j2
```
@universalvishwa hmm, /Library/Python/2.7/site-packages/ansible/galaxy/data/ looks wrong for ansible-2.3. There should be a 'default' and 'container_enabled' subdirs in there.

How was ansible installed?

Hi,

I followed this guide....
https://valdhaus.co/writings/ansible-mac-osx/
HI,

Assuming that I made a mistake during installation, I uninstalled ansible completely and reinstalled. I did check all installed paths and verified that '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages' is cleaned up. The issue is still the same. Here is the terminal output....

Please let me know if there is anything I can do to help you understand the issue more.
`
vseneviratne$ sudo pip uninstall ansible
.....`

```
vseneviratne$ sudo easy_install pip
Searching for pip
Best match: pip 9.0.1
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Installing pip3.5 script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Installing pip3 script to /Library/Frameworks/Python.framework/Versions/2.7/bin

Using /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
```

```
vseneviratne$ CC=clang sudo -E pip install pycrypto
The directory '/Users/vseneviratne/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/vseneviratne/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pycrypto in ./site-packages
```

```
vseneviratne$ sudo pip install ansible
The directory '/Users/vseneviratne/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/vseneviratne/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting ansible
  Downloading ansible-2.3.0.0.tar.gz (4.3MB)
    100% |████████████████████████████████| 4.3MB 317kB/s 
Requirement already satisfied: jinja2 in ./site-packages (from ansible)
Requirement already satisfied: PyYAML in ./site-packages (from ansible)
Requirement already satisfied: paramiko in ./site-packages (from ansible)
Requirement already satisfied: pycrypto>=2.6 in ./site-packages (from ansible)
Requirement already satisfied: setuptools in ./site-packages (from ansible)
Requirement already satisfied: MarkupSafe>=0.23 in ./site-packages (from jinja2->ansible)
Requirement already satisfied: cryptography>=1.1 in ./site-packages (from paramiko->ansible)
Requirement already satisfied: pyasn1>=0.1.7 in /Users/vseneviratne/Library/Python/2.7/lib/python/site-packages (from paramiko->ansible)
Requirement already satisfied: six>=1.6.0 in /Users/vseneviratne/Library/Python/2.7/lib/python/site-packages (from setuptools->ansible)
Requirement already satisfied: appdirs>=1.4.0 in ./site-packages (from setuptools->ansible)
Requirement already satisfied: packaging>=16.8 in ./site-packages (from setuptools->ansible)
Requirement already satisfied: cffi>=1.4.1 in ./site-packages (from cryptography>=1.1->paramiko->ansible)
Requirement already satisfied: idna>=2.1 in ./site-packages (from cryptography>=1.1->paramiko->ansible)
Requirement already satisfied: enum34 in ./site-packages (from cryptography>=1.1->paramiko->ansible)
Requirement already satisfied: asn1crypto>=0.21.0 in ./site-packages (from cryptography>=1.1->paramiko->ansible)
Requirement already satisfied: ipaddress in ./site-packages (from cryptography>=1.1->paramiko->ansible)
Requirement already satisfied: pyparsing in ./site-packages (from packaging>=16.8->setuptools->ansible)
Requirement already satisfied: pycparser in ./site-packages (from cffi>=1.4.1->cryptography>=1.1->paramiko->ansible)
Installing collected packages: ansible
  Running setup.py install for ansible ... done
Successfully installed ansible-2.3.0.0
```

```
vseneviratne$ ansible --version
ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
vseneviratne$ cd ansible/tmp/
vseneviratne$ ansible-galaxy init test5
- test5 was created successfully
vseneviratne$ ls test5
README.md defaults  handlers  meta      tasks     tests     vars
```
I can reproduce this with a fresh pip install in a clean env.

It looks like lib/ansible/galaxy/data/default/templates isnt getting picked up when packaged. Not sure why yet.
@alikins It looks like the `package_data` in `setup.py` doesn't match the directory itself nor the `.git_keep` file, and as such, the `templates` directory is not installed

Something like the following will grab the `.git_keep` file and the `templates` directory, although I question whether we want to bring the `.git_keep` file along:

```
            'galaxy/data/*/*/.*',
```


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -57,6 +57,7 @@
             'modules/windows/*.ps1',
             'modules/windows/*.ps1',
             'galaxy/data/*/*.*',
+            'galaxy/data/*/*/.*',
             'galaxy/data/*/*/*.*',
             'galaxy/data/*/tests/inventory'
         ],


Test patch: