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

IndexError on `ansible-galaxy install` when permissions denied on roles directory #149

Closed
issmirnov opened this Issue Nov 4, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@issmirnov

issmirnov commented Nov 4, 2017

Hi all,

Was setting up my server for some ansible work. Running an identical config to a previous machine, but seeing a critical issue when I run ansible-galaxy install issmirnov.dotfiles. It works on my other machine with is identical (same ansible version and OS).

ERROR! Unexpected Exception, this is probably a bug: list index out of range
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-galaxy", line 106, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/dist-packages/ansible/cli/galaxy.py", line 150, in run
    self.execute()
  File "/usr/lib/python2.7/dist-packages/ansible/cli/__init__.py", line 154, in execute
    fn()
  File "/usr/lib/python2.7/dist-packages/ansible/cli/galaxy.py", line 392, in execute_install
    installed = role.install()
  File "/usr/lib/python2.7/dist-packages/ansible/galaxy/role.py", line 332, in install
    self.path = self.paths[nextidx]
IndexError: list index out of range

While writing up this issue, I realized that the only difference in systems is that one user is root and the other isn't. After running chown -R /etc/ansible the installation worked fine.

It would be very timesaving if rather than IndexError: list index out of range galaxy checked for write permissions on the directory and surfaced a more user friendly message.

System information:

  • Ubuntu 16.04 ( 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux)

Ansible information:

ansible 2.4.1.0
  config file = /mnt/data1/Personal/Projects/ansible/ansible-vagrant/guacamole/linux/ansible.cfg
  configured module search path = [u'/usr/local/etc/ansible/library', u'/etc/ansible/library']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

@cutwater cutwater self-assigned this Nov 6, 2017

@cutwater

This comment has been minimized.

Show comment
Hide comment
@cutwater

cutwater Nov 7, 2017

Collaborator

@issmirnov Thank you for reporting this issue. Can you please provide additional information: which permissions had /etc/ansible directory when the issue occurred, did you execute ansible-galaxy as a regular user, did you use sudo or not?

As I can see ansible-galaxy installs role to home directory when executed by regular user, so any additional information that may help to reproduce this issue will be useful.

Collaborator

cutwater commented Nov 7, 2017

@issmirnov Thank you for reporting this issue. Can you please provide additional information: which permissions had /etc/ansible directory when the issue occurred, did you execute ansible-galaxy as a regular user, did you use sudo or not?

As I can see ansible-galaxy installs role to home directory when executed by regular user, so any additional information that may help to reproduce this issue will be useful.

@issmirnov

This comment has been minimized.

Show comment
Hide comment
@issmirnov

issmirnov Nov 7, 2017

Sure thing! I installed Ansible using the ppa (ppa:ansible/ansible). This created /etc/ansible and etc/Ansible/roles with permissions rwxr-xr-x root. On my server I have a regular non-root user (with sudo enabled) which I was using to run ansible-galaxy. My ansible.cfg file is shared across all machines, and looks like this:

[defaults]
remote_user=root
host_key_checking=False
inventory=hosts
library=/usr/local/etc/ansible/library:/etc/ansible/library
roles_path=/usr/local/etc/ansible/roles:/etc/ansible/roles

Looks like ansible-galaxy tried the two directories defined in roles_path, and while the first one didn't exist the second one just had the wrong permissions. Ideally ansible-galaxy would notify the user that the permissions need to be tweaked. Another option is to assume an implicit fallback to the home directory, but as a devops guy I'd rather have more fine grained control and have a chance to fix the issue then rerun the command rather than having the role install in an unexpected place.

issmirnov commented Nov 7, 2017

Sure thing! I installed Ansible using the ppa (ppa:ansible/ansible). This created /etc/ansible and etc/Ansible/roles with permissions rwxr-xr-x root. On my server I have a regular non-root user (with sudo enabled) which I was using to run ansible-galaxy. My ansible.cfg file is shared across all machines, and looks like this:

[defaults]
remote_user=root
host_key_checking=False
inventory=hosts
library=/usr/local/etc/ansible/library:/etc/ansible/library
roles_path=/usr/local/etc/ansible/roles:/etc/ansible/roles

Looks like ansible-galaxy tried the two directories defined in roles_path, and while the first one didn't exist the second one just had the wrong permissions. Ideally ansible-galaxy would notify the user that the permissions need to be tweaked. Another option is to assume an implicit fallback to the home directory, but as a devops guy I'd rather have more fine grained control and have a chance to fix the issue then rerun the command rather than having the role install in an unexpected place.

@xyalan

This comment has been minimized.

Show comment
Hide comment
@xyalan

xyalan Nov 10, 2017

I also have problems without sudo.With sudo everything is ok.

xyalan commented Nov 10, 2017

I also have problems without sudo.With sudo everything is ok.

gundalow pushed a commit to gundalow/ansible that referenced this issue Nov 14, 2017

Fix IndexError raised on galaxy-install
This patch fixes IndexError, that may be raised When trying
to install a role with `ansible-galaxy` in case of
access error to roles directory.

Issue: ansible/galaxy#149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment