HI All,
I am newbie for both Ansible and Jenkins and I looking for step by step approach for running ansible playbook for Jenkins.
From Jenkins, I have installed Ansible plugin and in Global Tool Configuration I have set path as /usr/bin. I am trying to create free-style project by selecting project name -->in build section → invoke ansible playbook → location of the script /home/ansible/script.yml. However, I am unable to run it.
Initially I have added my Jenkins and ansible to be same servers but after some googling, I have installed my ansible on slave node Jenkins. Jenkins and Slaves are installed in RHEL systems. My python version is 2.5. When I run playbook its getting executed as Jenkins user.
All I need is to run Jenkins job which will run ansible playbook. I am open to any approach if it fulfils my requirement
Thanks
Vamsi
It works fine. "Unable to run it" isn't really enough information;)
HI Malcolm,
Below is the error I am facing. I have placed script in /home/ansible. I believe this job is running as Jenkins user. Please suggest
Building on master in workspace /var/lib/jenkins/workspace/Ansible_create_user
[Ansible_create_user] $ sshpass ******** /usr/bin/ansible-playbook /home/ansible/create_user.yml -s -U ansible -f 5 -u ansible -k
e[0;35m[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of Ansible Become, e[0m
e[0;35mwhich is a generic framework. See become_user. , use become instead. This e[0m
e[0;35mfeature will be removed in version 2.8. Deprecation warnings can be disabled bye[0m
e[0;35m setting deprecation_warnings=False in ansible.cfg.e[0m
e[0;31mERROR! the playbook: /home/ansible/create_user.yml could not be founde[0m
FATAL: command execution failed
hudson.AbortException: Ansible playbook execution failed
at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:262)
at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:232)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1815)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
ERROR: Ansible playbook execution failed
Finished: FAILURE
Hi vamsi,
Play book error says there is no create_user.yml file is present in running directory . Check you are running from right directory .
HI Vinod,
As informed in my previous post, i have already placed script in the same path
root@servername#ls -l /home/ansible/create_user.yml
-rwxrwxrwx 1 ansible ansible 384 Aug 17 10:01 /home/ansible/create_user.yml
Regards
Vamsi
Jenkins usually operates on a ‘workspace’ which is different for each jenkins job.
So in your case it would expect to find files in /var/lib/jenkins/workspace/Ansible_create_user
not in /home/ansible/create_user.yml
You might find another tool provides tighter integration with your playbooks than Jenkins does ( for example AWX, or Tower) so might be worth trying other things if you are just starting out with both ansible and jenkins.
Jon
If you are using Jenkins & ansible it's better to store the playbooks/roles/inventories in git and use Jenkins to check it out. Makes developing easier imho
HI All,
Thanks for your suggestion.
I am able to resolve this issue. I have installed publish over ssh plugin from which I am able to run ansible playbook directly
PS:- My Jenkins and Ansible are on same server
Regards
Vamsi