使用Jenkins运行可播放的剧本时,出现以下错误。
Java.io.IOException: Cannot run program "/usr/bin/ansible-playbook" (in directory "/var/jenkins_home/workspace/ans"): error=2, No such file or directory
“
这就是我的Jenkinsfile中的内容
pipeline {
agent any
environment {
PATH = "/usr/bin/ansible:/usr/bin/ansible-playbook:$PATH"
ANS_HOME = tool('ansible')
}
stages {
stage('Example') {
steps {
echo "PATH is: $ANS_HOME"
sh "whoami"
sh "echo $PATH"
sh "/usr/bin/ansible-playbook -i /path /to/myinventory.ini /path/to/playbooks/myplaybook.yml --extra-vars '{\"mode\" : \"running\"}'"
}
}
}
}
正在以root用户身份运行,因为sh“ whoami”的输出是root。此外,路径还具有/ usr / bin,/ usr / bin / ansible和/ usr / bin / ansible-playbook
--------下面的输出------------------------------------- -
> [Pipeline] {
> [Pipeline] stage
> [Pipeline] { (Example)
> [Pipeline] echo
> PATH is: /usr/bin/
> [Pipeline] sh
> [t_AWS-DB-resource-scheduler-TM5AGTEATY6FDJ7IENKWVPBZAIMOHYN5WXTFRS72TMHS4V4L57UA]
> Running shell script
> ps: unrecognized option: p
> + whoami
> root
> [Pipeline] sh
> [t_AWS-DB-resource-scheduler-TM5AGTEATY6FDJ7IENKWVPBZAIMOHYN5WXTFRS72TMHS4V4L57UA]
> Running shell script
> ps: unrecognized option: p
> + echo /usr/bin/ansible:/usr/bin/ansible-playbook:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
> /usr/bin/ansible:/usr/bin/ansible-playbook:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
> [Pipeline] sh
> [t_AWS-DB-resource-scheduler-TM5AGTEATY6FDJ7IENKWVPBZAIMOHYN5WXTFRS72TMHS4V4L57UA]
> Running shell script
> ps: unrecognized option: p
> -o COL1,COL2=HEADER Select columns for display
> + /usr/bin/ansible-playbook -i /mnt/management/environments/localhost.ini
> /mnt/management/playbooks/utilities/aws-scheduler.yml --extra-vars
> {"mode" : "running"}
> /var/jenkins_home/workspace/t_AWS-DB-resource-scheduler-TM5AGTEATY6FDJ7IENKWVPBZAIMOHYN5WXTFRS72TMHS4V4L57UA@tmp/durable-ae31d6ed/script.sh:
> line 1: /usr/bin/ansible-playbook: not found
答案 0 :(得分:1)
我将按照以下步骤解决您的问题:
检查Jenkins用来从其运行剧本的文件夹是什么,此信息位于任务控制台中。
确保在运行任务后Jenkins没有清理存储库。
SSH进入Jenkins,并以jenkins用户的身份进入工作区jenkins。
确保所有文件都位于预期位置。
手动运行脚本。
如果可以手动运行命令,请确保将正确的命令放在管道上,请确保路径之间没有空格。 (之所以这样说是因为您粘贴的命令在“ /path”“/to/myinventory.ini”之间有空格)