最近在安裝ansible,安裝後命令找不到python
[root@center ansible-2.7.5]# python setup.py install
安裝後 查看相關版本vim
[root@center ansible-2.7.5]# ansible --version -bash: ansible: command not found
查看可執行文件目錄爲bash
[root@center ansible-2.7.5]# /usr/local/bin/ansible --version ansible 2.7.5 config file = None configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python2.7/site-packages/ansible-2.7.5-py2.7.egg/ansible executable location = /usr/local/bin/ansible python version = 2.7.8 (default, Jan 9 2019, 14:25:24) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] [root@center ansible-2.7.5]# echo $PATH /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
當前PATH 並無/usr/local/bin,所以須要將/usr/local/bin添加到環境變量中
下面列出三種添加方法spa
一、直接用export命令:命令行
export PATH=/usr/local/bin:$PATH [root@center ansible-2.7.5]# echo $PATH /usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 可是這種方法只會對當前用戶及當前命令行窗口生效,退出後就會丟失
二、編輯修改.bashrc文件:code
vim /root/.bashrc #在最後一行添上: export PATH=/usr/local/bin:$PATH 這種方法只會對當前用戶生效,需重啓系統
三、編輯修改profile文件:blog
vim /etc/profile export PATH=/usr/local/bin:$PATH 這種方法對全部用戶生效,需重啓系統 因此咱們配置時須要結合1-2或者1-3 配置完以後再次執行ansible [root@center ansible-2.7.5]# ansible --version ansible 2.7.5 config file = None configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python2.7/site-packages/ansible-2.7.5-py2.7.egg/ansible executable location = /usr/local/bin/ansible python version = 2.7.8 (default, Jan 9 2019, 14:25:24) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]