今天用jenkins 來執行在remote server 上執行 create folder 的時候,報錯:
看一下output log:
Console Output
Started by user sheng Building in workspace /var/lib/jenkins/workspace/Create folder in test2 system [Create folder in test2 system] $ ansible test2 -m file -a "path=/root/david/p state=directory" -f 5 0888d8a896a5 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).", "unreachable": true }
其實,這個報錯,可以通過建立一個jenkin 的用戶: sheng 來創建公鑰來解決, 但是在remote 機器上執行的時候,報權限問題,正確的解決方法是:
1.將jenkins賬號分別加入到root組中 gpasswd -a root jenkins (還有一種說法是:gpasswd -a jenkins root)
2.修改/etc/sysconfig/jenkins文件中, # user id to be invoked as (otherwise will run as root; not wise!)
JENKINS_USER=root
JENKINS_GROUP=root 可以修改爲root權限運行
3.重啓Jenkins service Jenkins restart
---
好,下面運行成功,看一下創建的文件的權限:
drwxr-xr-x. 2 root root 6 Dec 3 04:47 p
可以看到權限是root.
問題解決,OK!