在 Jenkins 中调用 Ansible playbook [英] Invoke Ansible playbook in Jenkins

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

问题描述

我有 jenkins 构建,我正在尝试调用 ansible playbook 文件进行 s3 上传.当我执行 post-build-script 以调用 ansible playbook 文件时,我以以下错误结束.无法运行程序ansible-playbook"(在目录/var/jenkins_home/workspace/mybuild"中):错误=2,没有那个文件或目录

下面的截图是 ansible 后构建脚本配置.

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

当我尝试直接在 jenkins 图像(终端)中运行 ansible-playbook myplaybook.yml 时,我最终得到 bash: ansible-playbook: command not found

当我尝试在我的 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.

出现错误是因为container的作者总是尽量精简,去掉包信息.

您不需要 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.

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

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