ansibleをpipでinstallする。
# python3 -m pip install --user ansible
installしたのにansibleが見つからない。
# ansible
-bash: ansible: コマンドが見つかりません
または(ansible: command not found)
以下のpythonの公式ドキュメントにも書かれているのだが、
Installing Packages — Python Packaging User Guide
On Linux and macOS you can find the user base binary directory by running
https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-to-the-user-sitepython -m site --user-base
and addingbin
to the end. For example, this will typically print~/.local
(with~
expanded to the absolute path to your home directory) so you’ll need to add~/.local/bin
to yourPATH
.
とのこと。
確かにrootユーザーのhome directoryで探すとansible(とその他もろもろ)が見つかった。
# find . | grep /bin/ansible
./.local/bin/ansible-galaxy
./.local/bin/ansible-pull
./.local/bin/ansible-config
./.local/bin/ansible-test
./.local/bin/ansible-playbook
./.local/bin/ansible-vault
./.local/bin/ansible
./.local/bin/ansible-doc
./.local/bin/ansible-console
./.local/bin/ansible-inventory
./.local/bin/ansible-connection
実際に直接指定すると確かにansibleが実行できた。
# ./.local/bin/ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current
version: 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]. 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.12]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /root/.local/lib/python3.7/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = ./.local/bin/ansible
python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]
jinja version = 2.10
libyaml = False
そこでpathを通すことにする。以下のサイトを参考にする。
bash – How to permanently set $PATH on Linux/Unix – Stack Overflow
~/.bashrcというファイルの最後の行に「export PATH=”$PATH:/root/.local/bin”」を追記する。
設定を反映するために以下のコマンドを打つ。
# source ~/.bashrc
で、ansibleが使えるようになった。
# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current
version: 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]. 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.12]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /root/.local/lib/python3.7/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /root/.local/bin/ansible
python version = 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]
jinja version = 2.10
libyaml = False