简体   繁体   English

如何在詹金斯执行Ansible剧本

[英]How to execute ansible playbook in Jenkins

I want to run a playbook using Jenkins. 我想用詹金斯玩一本剧本。 I have Docker installed in windows 10 machine. 我在Windows 10计算机上安装了Docker。 Through Docker I brought up a local Jenkins, and I installed GIT and Ansible plugin in it. 通过Docker,我带来了一个本地的Jenkins,并在其中安装了GIT和Ansible插件。

Now if the Jenkins job gets triggered, my playbook is getting downloaded from GIT to my Jenkins workspace. 现在,如果触发了Jenkins作业,我的剧本将从GIT下载到我的Jenkins工作区。 From my workspace I am trying to run the playbook. 从我的工作区,我试图运行剧本。 When I trigger the build job I am facing issue after checkout from GIT as follows: 当我触发构建作业时,我从GIT签出后面临如下问题:

[MyFirstJob] $ sshpass ******** /usr/bin/ansible-playbook /usr/bin -l "${group} /hostname" -f 5 -u dinesh -k
FATAL: command execution failed
java.io.IOException: Cannot run program "sshpass" (in directory "/var/jenkins_home/workspace/MyFirstJob"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at hudson.Proc$LocalProc.<init>(Proc.java:249)
    at hudson.Proc$LocalProc.<init>(Proc.java:218)

I do not have Ansible installed in my local machine. 我的本地计算机上未安装Ansible。 Do I need to install it in my local ? 我需要在本地安装它吗? Or any other steps to run my ansible playbook through my local Jenkins. 或任何其他步骤来通过我的本地Jenkins运行我的ansible手册。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

To explain the main error you are seeing, it looks like you don't have the sshpass program installed where Jenkins is running, in a container it sounds like. 为了解释您所看到的主要错误,听起来您好像没有在Jenkins运行所在的sshpass安装sshpass程序。

I say "where Jenkins is running" because it seems like you are confusing the execution space where the container is running with your local system's execution space where docker is running. 我之所以说“ Jenkins在哪里运行”,是因为您似乎将容器在运行的执行空间与本地系统在docker运行的执行空间混为一谈。

Yes, you will need to have ansible installed but it needs to be installed inside the container where Jenkins is running. 是的,您将需要安装ansible,但需要将其安装在运行Jenkins的容器内。 Jenkins won't be able to access any programs running on your local system if its running inside a container. 如果Jenkins在容器中运行,它将无法访问在本地系统上运行的任何程序。 You can share filesystems and some processes, but essentially the container needs to have Jenkins, sshpass , and ansible installed. 您可以共享文件系统和某些进程,但实际上,容器需要安装Jenkins, sshpass sshpass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM