使用詹金斯执行Ansible Playbook [英] Executing Ansible Playbook using Jenkins

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

问题描述

我知道这里有一个相关的问题:在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,也是如此(创建了一个项目,并在运行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

我对此一无所知,并且不执行此操作就无法继续进行下一步.谁能帮我解决我缺少的其他配置(可能在詹金斯方面).任何帮助将不胜感激.

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用户下执行的,该用户无权访问ansible/jenkins主机上的/home/ec2-user/.ssh/Host_Keypair.pem密钥以在远程服务器上进行身份验证.

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:权限被拒绝

no such identity: /home/ec2-user/.ssh/Host_Keypair.pem: Permission denied

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

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