Why can't I find ansible when I install it using setup.py?
Question:
Because I had some trouble with Ansible (I’m on mac) which seemed to be fixed in the latest dev version today I uninstalled ansible through pip (sudo pip uninstall ansible
) and reinstalled the latest dev version from the github repo using the classic setup.py method, which seemed to end successfully (full output here.
So then I tried using it:
$ ansible --version
-bash: ansible: command not found
$ which ansible
$
I checked where it is installed. From the full output I linked to above I found that it is installed in /usr/local/lib/python2.7/site-packages
, and indeed in there I find an egg:
$ ls -l /usr/local/lib/python2.7/site-packages | grep ansible
drwxr-xr-x 4 root admin 136 Aug 22 16:33 ansible-2.4.0-py2.7.egg
When I start Python and check the site-packages folder I find a different folder:
>>> import site; print site.getsitepackages()[0]
/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
but that is a symlink to the same folder:
$ ls -l /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
lrwxr-xr-x 1 hielke admin 54 Aug 13 22:36 /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages -> ../../../../../../../../../lib/python2.7/site-packages
So I guess the problem is that no symlink is created to the ansible package in /usr/local/bin/
. But I’m unsure how I could create such a symlink and why it wouldn’t appear in the first place.
Does anybody know how I can move forward from here? All tips are welcome!
Answers:
I suggest uninstalling Ansible and re-installing it using pip
according to the method suggested in the Ansible docs:
Or if you are looking for the latest development version:
pip install git+https://github.com/ansible/ansible.git@devel
If you are installing on OS X Mavericks, you may encounter some noise from your compiler. A workaround is to do the following:
$ sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install ansible
Readers that use virtualenv can also install Ansible under virtualenv, though we’d recommend to not worry about it and just install Ansible globally. Do not use easy_install to install ansible directly.
When you invoke ansible
from the shell, bash will search in your $PATH
for a file named ansible that is executable. This may not be the only issue, but this is the immediate cause for the error you’re seeing. The .egg
file itself is not an executable, it’s just a file used for distributing the code.
If ansible has been installed correctly, you should be able to find it by using locate or the OSX Finder GUI. The name should match exactly, with no file extensions. You will probably also find ansible-connection
, ansible-console
, etc. in the same place where you find the ansible
executable. If you find it, great! Test it out and add that directory to your $PATH
in a terminal like so:
export PATH=$PATH:/path/to/ansible
Where /path/to/ansible
is the directory where you found the executables. This change to the $PATH
variable is temporary, and will go away when you close your shell. If you can now run ansible from bash, then you can make the change permanent by adding that export to the end of your $HOME/.bash_profile
file, or by adding a rule in /etc/paths.d
(recommended by Apple). See more on how exactly to do those here if you are unfamiliar with them.
Now, if that’s not the problem and you can’t find the ansible
executable, then the installation itself is your problem. You might also try using a virtual environment (if you have it installed) to make sure that the version you’re pulling from github isn’t broken:
git clone https://github.com/ansible/ansible.git
cd ansible
virtualenv venv
source venv/bin/activate
pip install .
which ansible
As of this writing, the above gives me a working ansible
install.
Find where ansible reside on your Mac. Most times its /Users/<yourusername>/Library/Python/3.7/bin
or /Users/<yourusername>/Library/Python/2.7/bin
. Then …
export PATH=$PATH:/Users/<yourusername>/Library/Python/3.7/bin
You can store this in your .bashrc
file.
Well, I think you just need to create a soft link
ln -s /Users/${yourname}/Library/Python/${python version}/bin/ansible /usr/local/bin/ansible
I faced same issue when I installed ansible. Run the below commands to solve the issue. But we have to active each time when we open a bash session if we want to use ansible.
$ python -m virtualenv ansible
$ source ansible/bin/activate
$ pip install ansible
I’m using zsh so in my /Users/arojas/.zshrc
I add this line that’s where my Ansible got installed by Python
export PATH="$PATH:$HOME/Library/Python/3.7/bin"
I faced the same issue and after have installed it used pip3 install ansible
it all works now.
For those using the Windows 10 Ubuntu terminal, running this command should fix the issue:
export PATH=$PATH:~/.local/bin
system/instance used: ec2 RH8, as root
# pip3 install ansible (not recommended - should be by a user)
# ansible --version ( not found - wtf?!)
# yum install mlocate
# update
# locate ansible (long output; scroll to where you input command)
# export PATH=$PATH:/usr/local/bin
# ansible --version (success, Yes!)
system/instance used: ec2 RH8, as root
# pip3 install ansible (not recommended - should be by a user)
# ansible --version ( not found - :( )
# yum install mlocate
# updatedb (updatedb creates or updates a database used by locate)
# locate ansible (TL;DR)
# export PATH=$PATH:/usr/local/bin (Add this line to .bashrc)
# source .bashrc (To reflect the changes in the bash)
# ansible --version (success, Yes!)
pip3 install ansible --user
this installs in ~/.local. just include this in PATH, it will work
example: export PATH="$PATH:~/.local/bin"
Because I had some trouble with Ansible (I’m on mac) which seemed to be fixed in the latest dev version today I uninstalled ansible through pip (sudo pip uninstall ansible
) and reinstalled the latest dev version from the github repo using the classic setup.py method, which seemed to end successfully (full output here.
So then I tried using it:
$ ansible --version
-bash: ansible: command not found
$ which ansible
$
I checked where it is installed. From the full output I linked to above I found that it is installed in /usr/local/lib/python2.7/site-packages
, and indeed in there I find an egg:
$ ls -l /usr/local/lib/python2.7/site-packages | grep ansible
drwxr-xr-x 4 root admin 136 Aug 22 16:33 ansible-2.4.0-py2.7.egg
When I start Python and check the site-packages folder I find a different folder:
>>> import site; print site.getsitepackages()[0]
/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
but that is a symlink to the same folder:
$ ls -l /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
lrwxr-xr-x 1 hielke admin 54 Aug 13 22:36 /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages -> ../../../../../../../../../lib/python2.7/site-packages
So I guess the problem is that no symlink is created to the ansible package in /usr/local/bin/
. But I’m unsure how I could create such a symlink and why it wouldn’t appear in the first place.
Does anybody know how I can move forward from here? All tips are welcome!
I suggest uninstalling Ansible and re-installing it using pip
according to the method suggested in the Ansible docs:
Or if you are looking for the latest development version:
pip install git+https://github.com/ansible/ansible.git@devel
If you are installing on OS X Mavericks, you may encounter some noise from your compiler. A workaround is to do the following:
$ sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install ansible
Readers that use virtualenv can also install Ansible under virtualenv, though we’d recommend to not worry about it and just install Ansible globally. Do not use easy_install to install ansible directly.
When you invoke ansible
from the shell, bash will search in your $PATH
for a file named ansible that is executable. This may not be the only issue, but this is the immediate cause for the error you’re seeing. The .egg
file itself is not an executable, it’s just a file used for distributing the code.
If ansible has been installed correctly, you should be able to find it by using locate or the OSX Finder GUI. The name should match exactly, with no file extensions. You will probably also find ansible-connection
, ansible-console
, etc. in the same place where you find the ansible
executable. If you find it, great! Test it out and add that directory to your $PATH
in a terminal like so:
export PATH=$PATH:/path/to/ansible
Where /path/to/ansible
is the directory where you found the executables. This change to the $PATH
variable is temporary, and will go away when you close your shell. If you can now run ansible from bash, then you can make the change permanent by adding that export to the end of your $HOME/.bash_profile
file, or by adding a rule in /etc/paths.d
(recommended by Apple). See more on how exactly to do those here if you are unfamiliar with them.
Now, if that’s not the problem and you can’t find the ansible
executable, then the installation itself is your problem. You might also try using a virtual environment (if you have it installed) to make sure that the version you’re pulling from github isn’t broken:
git clone https://github.com/ansible/ansible.git
cd ansible
virtualenv venv
source venv/bin/activate
pip install .
which ansible
As of this writing, the above gives me a working ansible
install.
Find where ansible reside on your Mac. Most times its /Users/<yourusername>/Library/Python/3.7/bin
or /Users/<yourusername>/Library/Python/2.7/bin
. Then …
export PATH=$PATH:/Users/<yourusername>/Library/Python/3.7/bin
You can store this in your .bashrc
file.
Well, I think you just need to create a soft link
ln -s /Users/${yourname}/Library/Python/${python version}/bin/ansible /usr/local/bin/ansible
I faced same issue when I installed ansible. Run the below commands to solve the issue. But we have to active each time when we open a bash session if we want to use ansible.
$ python -m virtualenv ansible
$ source ansible/bin/activate
$ pip install ansible
I’m using zsh so in my /Users/arojas/.zshrc
I add this line that’s where my Ansible got installed by Python
export PATH="$PATH:$HOME/Library/Python/3.7/bin"
I faced the same issue and after have installed it used pip3 install ansible
it all works now.
For those using the Windows 10 Ubuntu terminal, running this command should fix the issue:
export PATH=$PATH:~/.local/bin
system/instance used: ec2 RH8, as root
# pip3 install ansible (not recommended - should be by a user)
# ansible --version ( not found - wtf?!)
# yum install mlocate
# update
# locate ansible (long output; scroll to where you input command)
# export PATH=$PATH:/usr/local/bin
# ansible --version (success, Yes!)
system/instance used: ec2 RH8, as root
# pip3 install ansible (not recommended - should be by a user)
# ansible --version ( not found - :( )
# yum install mlocate
# updatedb (updatedb creates or updates a database used by locate)
# locate ansible (TL;DR)
# export PATH=$PATH:/usr/local/bin (Add this line to .bashrc)
# source .bashrc (To reflect the changes in the bash)
# ansible --version (success, Yes!)
pip3 install ansible --user
this installs in ~/.local. just include this in PATH, it will work
example: export PATH="$PATH:~/.local/bin"