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 in Ansible by Asha
218 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 by Aman

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer
0 votes
3 answers
0 votes
1 answer

Permission denied when running ansible playbook through jenkins

Jenkins uses it's own user to execute ...READ MORE

answered Jun 25, 2018 in Ansible by DareDev
• 6,810 points
552 views
0 votes
0 answers

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

Not able to connect remote host via ...READ MORE

Apr 2 in Jenkins by Nishant
• 160 points

recategorized Apr 2 by Nishant 566 views
+13 votes
2 answers
0 votes
1 answer

Error when executing ansible playbook on Azure

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

answered Jan 28 in Ansible by Kavya
28 views