再現手順
sudo でrootユーザーの実行権限で、次のようなplaybookを実行したら発生する。
playbook.yml
- hosts: localhost
connection: local
tasks:
- name: clone github repos
tags: github
sudo: no
git:
repo: https://github.com/cubicdaiya/slackboard.git
dest: $HOME/slackboard
現象
次のようなエラーが発生してリポジトリをCloneできない。
TASK [clone github repos] ******************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to find required executable git"}
原因
sudoで実行するrootユーザーに、gitのPATHが通っていないため、gitが実行できない。
対応方法
昔は、sudo=no
をtaskに指定すればよかったが、Ansible 1.9 から非推奨になっている。
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).
becomを使うことが推奨されている。