Ansible の複数バージョンを virtualenv で管理する
- 2019 8/6
Ansible を使い始めて最初にハマったことは、パスワードなしで SSH 接続できるサーバには ansible-playbook コマンドの -k, –ask-pass オプションを付けるとエラーになるということでした。
ansible-playbook コマンドの help によると -k, –ask-pass は接続時にパスワードを求めるオプションみたいです。
$ ansible-playbook -h Usage: ansible-playbook playbook.yml Options: -k, --ask-pass ask for connection password |
以下、エラー時の実行結果です。
$ ansible-playbook -k -c paramiko -i hosts init.yml -vvv --extra-vars "user_password=$user_password" No config file found; using defaults SSH password: PLAYBOOK: init.yml ****************************************************** 1 plays in init.yml PLAY [setting SakuraServer VPS by root] **************************************** TASK [setup] ******************************************************************* <128.199.213.164> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO 128.199.213.164 paramiko: The authenticity of host '128.199.213.164' can't be established. The ssh-rsa key fingerprint is 99a7fb117513602f560568e9d6daaa72. Are you sure you want to continue connecting (yes/no)? yes fatal: [128.199.213.164]: UNREACHABLE! => {"changed": false, "msg": "Authentication failed.", "unreachable": true} to retry, use: --limit @init.retry PLAY RECAP ********************************************************************* 128.199.213.164 : ok=0 changed=0 unreachable=1 failed=0 |
公開鍵認証による SSH 接続設定をしていて、ログインパスワードが不要な場合は -k, –ask-pass オプションを付けると下記のように The authenticity of host ‘128.199.213.164’ can’t be established. というエラーが発生してしまいます。
$ ansible-playbook -h Usage: ansible-playbook playbook.yml Options: -k, --ask-pass ask for connection password |
-k オプションを付けずに ansible-playbook コマンドを実行すると正常に実行できました。
$ ansible-playbook -c paramiko -i hosts init.yml -vvv |
以上です。
Ansible 2 系を brew コマンドを使ってサクッと Mac にインストールしました。
$ brew info ansible ansible: stable 2.0.2.0 (bottled), devel 2.0.2.0-0.4.rc4, HEAD Automate deployment, configuration, and upgrading https://www.ansible.com/ Not installed From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ansible.rb ==> Dependencies Build: pkg-config ✘ Required: libyaml ✘, openssl ✘ ==> Caveats Homebrew writes wrapper scripts that set PYTHONPATH in ansible's execution environment, which is inherited by Python scripts invoked by ansible. If this causes problems, you can modify your playbooks to invoke python with -E, which causes python to ignore PYTHONPATH. |
$ brew install ansible |
$ ansible --version ansible 2.0.2.0 config file = configured module search path = Default w/o overrides |
以上です。