简体   繁体   中英

zsh: command not found: ansible after pip installing

I've installed ansible on my Mac using pip as advised by ansible's documentation: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-macos

However when I try to run ansible I get the following: zsh: command not found: ansible

I've never had this problem when installing ansible before.

pip-installing again tells me it's already installed under site packages: Requirement already satisfied: ansible in./Library/Python/3.8/lib/python/site-packages (2.9.11)

And my python installation in ~/.zshrc points to:

# Add user python 3.7 to path
export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Might be obvious to some but I can't figure out why this simple installation isn't working..

After installing ansible with python3 -m pip install --user ansible , I searched for the ansible binary and found it to be downloaded into ~/Library/Python/3.8/bin . The simplest way is to figure this out is:

$ cd ~
$ find . | grep ansible
<lines omitted>
./Library/Python/3.8/bin/ansible
<lines omitted>

From there, its pretty easy, just update your.bash_profile or.zshrc with

export PATH="/path/to/Library/Python/3.8/bin:$PATH"

And you should be good to go:

$ source ~/.zshrc
$ ansible --version
ansible 2.10.8
  config file = None
  configured module search path = ['/Users/dbove/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

brew install ansible
brew link ansible

Uninstall ansible sudo pip uninstall ansible .
Then install by using pip3 sudo pip3 install ansible .
Check the version by using ansible --version .

ansible 2.10.3

Note : Make sure you have pip3 installed, In case you don't have then install by using brew install python3

Below commands worked for me:

Uninstall ansible

sudo pip uninstall ansible

Then install by using (Note: -H flag is important here which sets HOME variable to target user's home dir)

sudo -H pip3 install ansible

Check the version by using

ansible --version

I had multiple ansible instances. I followed the steps below and rectified the ansible command not found error.

  1. Uninstall old /all instances of ansible
python3 -m pip uninstall ansible
python3 -m pip uninstall ansible-core
  1. Find all instances of ansible
cd ~
find . | grep ansible
  1. Remove all directories from step 2
rm -rf /usr/local/lib/python3.6/site-packages/ansible*
rm -rf /root/.local/lib/python3.6/site-packages/ansible
rm -rf ./.ansible
rm -rf ./.local/lib/python3.6/site-packages/ansible_test
  1. Install ansible once again
sudo yum install python3-pip 
pip3 install ansible
pip3 install openshift
  1. Validate
pip3 list  | grep ansible
ansible (4.8.0)
ansible-core (2.11.6)
ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Sep 12 2021, 04:40:35) [GCC 
8.4.1 20200928 (Red Hat 8.4.1-1)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False 
in ansible.cfg.
ansible [core 2.11.6] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.6.8 (default, Sep 12 2021, 04:40:35) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 3.0.2
  libyaml = True

i was seeing same error, i was missing ansible-lint

brew install ansible
brew install ansible-lint

after installing like:

python3 -m pip install --user ansible

edit.zshrc:

export PATH=$HOME/bin:/usr/local/bin:$HOME/.local/bin:$PATH

You shoud add $HOME/.local/bin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM