在詹金斯中调用Ansible剧本 [英] Invoke Ansible playbook in Jenkins

查看:149
本文介绍了在詹金斯中调用Ansible剧本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有jenkins版本,并且正在尝试为an s3上传调用ansible剧本文件.当我执行用于调用ansible剧本文件的构建后脚本时,我将出现以下错误. 无法运行程序"ansible-playbook"(在目录"/var/jenkins_home/workspace/mybuild"中):error = 2,没有此类文件或目录

下面的屏幕截图是可配置的后构建脚本.

仅供参考:我的构建文件夹中有一个文件(ansibledemo.yml).我尝试给出绝对路径(/var/jenkins_home/workspace/mybuild/ansibledemo.yml).还是不行.

当我尝试直接在jenkins图像(终端)中运行ansible-playbook myplaybook.yml时,我最终会遇到 bash:ansible-playbook:找不到命令

当我尝试在jenkins服务器中安装ansible时,无法执行任何安装命令.请看下面的截图.

解决方案

  1. 从已配置的源下载软件包信息.

    # apt update

  2. 安装ansible

    # apt install ansible

就是这样.

如果您运行的是官方的jenkins容器(基于debian),而不是已经安装了ansible的repo,则不需要"apt-add-repository".但是您可以通过安装常用的software-properties-common来安装apt-add-repository,以供进一步使用.

dpkg -S apt-add-repository告知此数据包属于software-properties-common.

出现错误是因为容器的作者总是试图使容器尽可能轻,并删除包装信息.

您不需要sudo,因为默认情况下您成为root用户.仅当您有意提及时,您才能成为另一个用户.

请在您的问题中添加您在容器中使用的信息.

I have jenkins build and I am trying to invoke a ansible playbook file for an s3 upload. When I execute a post-build-script for invoking an ansible playbook file, I am ending with below error. Cannot run program "ansible-playbook" (in directory "/var/jenkins_home/workspace/mybuild"): error=2, No such file or directory

Below screenshot is ansible post build script configuration.

FYI: There is a file(ansibledemo.yml) in my build folder. I tried giving absolute path(/var/jenkins_home/workspace/mybuild/ansibledemo.yml). Still no go.

When I try running ansible-playbook myplaybook.yml directly in jenkins image(terminal) I am ending up with bash: ansible-playbook: command not found

When I tried installing ansible in my jenkins server, I couldn't execute any installation commands. Please see the below screenshot.

解决方案

  1. Download package information from the configured sources.

    # apt update

  2. Install ansible

    # apt install ansible

That's it.

If you run official jenkins container (based on debian) than repo with ansible build in already and you don't need "apt-add-repository". But you could install apt-add-repository by installing software-properties-common for further using.

dpkg -S apt-add-repository tells that this packet belongs to software-properties-common.

Error appears because the author of container always tries to make it as light as possible and remove package information.

You don't need sudo, because you become root in container by default. You become another user only if you mention it in intentionally.

Please, add information that you work in container to your question.

这篇关于在詹金斯中调用Ansible剧本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆