使用 Jenkins 执行 Ansible Playbook [英] Executing Ansible Playbook using Jenkins
问题描述
我知道这里有一个相关的问题:在 Jenkins 中调用 Ansible 剧本一个>
I know there's a related question here: Invoke Ansible playbook in Jenkins
但是这个问题在某些方面与那个不同:
But this question is different from that in some perspectives:
所以我在单个服务器(EC2 实例)中安装了 Jenkins 和 Ansible.我创建了一个 playbook.yml,它将文件从这台服务器复制到另一台服务器.如果我使用 ec2-user 执行 ansible-playbook playbook.yml,这是成功的.
So I have Jenkins and Ansible installed in a single server (EC2 instance). I have created a playbook.yml which copies files from this server to another server. This is successful if I do ansible-playbook playbook.yml using ec2-user.
如果我尝试使用 Jenkins(创建一个项目并添加一个构建步骤作为 run ansible playbook 并提到 playbook.yml 的位置并以 sudo ec2-user 身份运行),也是如此.这是失败的错误:
The same if I try to do using Jenkins (Created a project and added a build step as run ansible playbook and mentioned the location of playbook.yml and running as sudo ec2-user). This is failing with the error:
fatal: [172.xx.xx.xx]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity: /home/ec2-user/.ssh/Host_Keypair.pem: Permission denied\r\nPermission denied (publickey).\r\n", "unreachable": true}
to retry, use: --limit @/var/lib/jenkins/workspace/Ansible/copy.retr
playbook.yml:
playbook.yml:
---
- hosts: 172.xx.xx.xx
remote_user: ec2-user
become: yes
become_method: sudo
tasks:
- copy:
src: /var/lib/jenkins/workspace/Ansible/myfile.conf
dest: /etc/myfile.conf
owner: ec2-user
group: ec2-user
mode: 0644
我被困在这个问题上,如果不执行它就无法进入下一步.任何人都可以帮助我了解我缺少的其他配置(可能在 Jenkins 方面).任何帮助将不胜感激.
I am stuck on this and not able to move to next step without executing this. Can anyone please help me on what other configuration I am missing (possibly in Jenkins side). Any help would be much appreciated.
推荐答案
Playbook 在 jenkins
用户下执行,该用户无权访问 /home/ec2-user/.ssh/Host_Keypair.pem
密钥在 ansible/jenkins 主机上以在远程服务器上进行身份验证.
Playbook is executed under jenkins
user which doesn't have access to /home/ec2-user/.ssh/Host_Keypair.pem
key on ansible/jenkins host to authenticate on remote server.
有一条错误信息:
没有这样的身份:/home/ec2-user/.ssh/Host_Keypair.pem: Permission denied
no such identity: /home/ec2-user/.ssh/Host_Keypair.pem: Permission denied
这篇关于使用 Jenkins 执行 Ansible Playbook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!