Invoke Ansible playbook in Jenkins

走远了吗. 提交于 2019-12-13 06:11:47

问题


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:


Ansible is not install on your Jenkins machine, first you need to install the ansible on the jenkins machine:

On Ubuntu/Debian:

sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

On CentOS/RedHat:

sudo yum install epel-release
sudo yum install ansible

After that you will be able to run the ansible-playbook.




回答2:


You can try to install using pip version as an alternative and try, Please see the below steps,

$ virtualenv venv
$ source venv/bin/activate
$ pip install ansible-container[docker,openshift]

You can see more options to install in docs: https://docs.ansible.com/ansible-container/installation.html

But always it is a good option to keep a separate vm / docker like "ansible-controller" and use that as a slave to jenkins, So that you don't need ansible plugins in ansible. And jenkins will be always stable without much load




回答3:


  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.



来源:https://stackoverflow.com/questions/41771060/invoke-ansible-playbook-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!