gpt4 book ai didi

jenkins - 在 jenkins 管道上运行 ansible playbook

转载 作者:行者123 更新时间:2023-12-02 10:54:53 25 4
gpt4 key购买 nike

我打开这个主题是因为当我尝试在 Jenkins 管道中运行 ansiblePlaybook 时遇到问题。插件 ansible 已安装并启用。我写了一个 Jenkinsfile,在其中设置环境并调用我的 ansible 管道,如下所示:

enter image description here

就像你所看到的,我还验证了我的 ansible 位于路径中并且它识别了它。但它无法运行它。下面的输出有错误:

enter image description here

我还尝试像 shell 命令一样运行它:

enter image description here

但它无法到达我的服务器,ssh 连接失败:

enter image description here

但是当我在自由式工作中使用 ansible 时,它​​运行良好,所以我不明白为什么!

希望有人可以帮助我解决这个问题,并为第二个问题找到解决方案,这样我就可以有一个临时解决方案。如果我的英语不好,请原谅我,这不是我的母语。

问候,

最佳答案

首先感谢 Matt Schuchard 和 Jimit Raithatha 的回答。我找到了如何解决我的问题。我使用 ansible 插件并使用以下代码添加 ansible :

withEnv(["PATH+ANSIBLE"=${tool 'name of the tool in tool configuration'}])

但是 withEnv 仅适用于 shell 命令(sh '...'),并且不能像我对 ansiblePlaybook 那样使用 Java 调用。命令 ansiblePlaybook 有一个参数,允许用户指定要使用的工具在哪里,我们只需添加以使用自定义工具配置中指定的名称的参数,对于 ssh 错误我根本没有配置我的 sshagent;这是一个例子:

    sshagent (credentials: ['name of the credential']) {
ansiblePlaybook(
credentialsId: id of the credential',
inventory: 'inventory file',
installation: 'name of the tool specified on the configuration tool screen',
limit: 'host where run the playbbok',
playbook: 'path to the playbook',
extras: ' options and var that you want add for instance verbose mode : -vvv'
)
}

希望有同样问题的人可以通过这个主题得到帮助!

问候,

关于jenkins - 在 jenkins 管道上运行 ansible playbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49942706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com