ERROR Ansible playbook execution failed - Ansible Jenkins

0 votes

I have a playbook and I'm trying to execute it using the Jenkins pipeline. 

pipeline script:

withEnv(["PYTHONPATH=/home/ec2-user/ansible/lib"]) {
                ansiblePlaybook([
                    colorized: true,
                    credentialsId: 'my-creds',
                    installation: 'ansible-2-2-0',
                    inventory: 'staging',
                    playbook: 'deploy.yml',
                    extras: "--extra-vars 'app_build_id=${git_commit}'"
                ])

            }
output:
[Pipeline] ansiblePlaybook
[planet-healthcare-pipeline] $ /home/ec2-user/ansible/bin/ansible-playbook deploy.yml -i staging -f 5 --private-key /home/ec2-user/jenkins/workspace/REDACTED.key -u ec2-user --extra-vars app_build_id=24a6431
Traceback (most recent call last):
  File "/home/ec2-user/ansible/bin/ansible-playbook", line 43, in <module>
    import ansible.constants as C
ImportError: No module named ansible.constants
FATAL: command execution failed
hudson.AbortException: Ansible playbook execution failed
    at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:227)
    at org.jenkinsci.plugins.ansible.workflow.AnsiblePlaybookStep$AnsiblePlaybookExecution.run(AnsiblePlaybookStep.java:290)
    at org.jenkinsci.plugins.ansible.workflow.AnsiblePlaybookStep$AnsiblePlaybookExecution.run(AnsiblePlaybookStep.java:226)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52)
    at hudson.security.ACL.impersonate(ACL.java:221)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] mail
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Ansible playbook execution failed
Finished: FAILURE
Apr 4, 2019 in Ansible by Asha
11,144 views

1 answer to this question.

0 votes

Hey @Asha, Try to run it as user jenkins

sudo su -s /bin/bash jenkins
answered Apr 4, 2019 by Aman

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer
+1 vote
3 answers
0 votes
1 answer

Not able to connect remote host via jenkins to run ansible playbook

set "host_key_checking = False" in /etc/ansible/ansible.cfg READ MORE

answered Dec 2, 2019 in Jenkins by pavan

reshown Dec 2, 2019 by Vardhan 10,215 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
0 votes
1 answer

Error when executing ansible playbook on Azure

Hey @Ganga, As the error message says, ...READ MORE

answered Jan 29, 2019 in Ansible by Kavya
1,033 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP