ansible 実行時に tmp ファイルに権限がないって怒られて失敗する
問題
rundeck から ansible 実行時に以下のエラーで ansible が失敗する。
Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of `/tmp/ansible-tmp-1539668029.49-46797233464078/': Operation not permitted chown: changing ownership of `/tmp/ansible-tmp-1539668029.49-46797233464078/command.py': Operation not permitted }). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user
このエラーは、 以下のように ssh ユーザ(ssh_user) と become-user (exec_user)で別のユーザを設定したときに発生する。 以下のように ssh ユーザ(ssh_user) でそのまま ansible 実行した場合はこのエラーは発生しない。
ansible -i <inventory_file> <hostname> -u <ssh_user >-m shell -a "git clone git@github.com:maomaomaopan/test_repo.git" --become-method sudo --become-user exec_user
調べてみると、いくつか同様の自称でバグレポートが。 https://github.com/ansible/awx/issues/389 https://github.com/ansible/ansible/issues/35089
対応手順としては、エラーメッセージにかいてある通り、以下ページのとおりにすればよかった☺ https://docs.ansible.com/ansible/latest/user_guide/become.html#becoming-an-unprivileged-user
解決方法
- パイプラインを有効にする
ansible.cfg
[defaults] pipelining = True
rundeck プロセス再起動してもう一度ジョブ実行してもなぜか同様のメッセージでエラーになる。 まだ /tmp 下にファイル配置しているようだ。
- /tmp 下の一時ファイルを誰でも書き込み可能にする
ansible.cfg
[defaults] allow_world_readable_tmpfiles = True
根本解決にはなってないけどいったんこれで対応しておわり。