Jenkins - Ansible integration

184 views
Skip to first unread message

Vamsi Krishna

unread,
Aug 19, 2018, 6:46:58 AM8/19/18
to Ansible Project

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

Malcolm Hussain-Gambles

unread,
Aug 19, 2018, 12:43:34 PM8/19/18
to Ansible Project
It works fine. "Unable to run it" isn't really enough information;)

Vamsi Krishna

unread,
Aug 20, 2018, 1:29:04 AM8/20/18
to Ansible Project
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
 [0;35m[DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of Ansible Become,  [0m
 [0;35mwhich is a generic framework. See become_user. , use become instead. This  [0m
 [0;35mfeature will be removed in version 2.8. Deprecation warnings can be disabled by [0m
 [0;35m setting deprecation_warnings=False in ansible.cfg. [0m
 [0;31mERROR! the playbook: /home/ansible/create_user.yml could not be found [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

vinoth kumar

unread,
Aug 20, 2018, 1:37:17 AM8/20/18
to ansible...@googlegroups.com
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 . 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/14749241-08d0-43d4-bdf5-b30ed171c0c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vamsi Krishna

unread,
Aug 20, 2018, 2:48:56 AM8/20/18
to Ansible Project
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

J Hawkesworth

unread,
Aug 20, 2018, 8:22:26 AM8/20/18
to Ansible Project
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

Malcolm Hussain-Gambles

unread,
Aug 20, 2018, 2:34:33 PM8/20/18
to Ansible Project
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

Vamsi Krishna

unread,
Aug 21, 2018, 11:57:33 PM8/21/18
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages