如何从jenkins- Pipeline运行ansible playbooks

时间:2018-04-05 13:50:12

标签: jenkins jenkins-plugins jenkins-pipeline

我有一个简单的手册来从S3下载文件,如下所示

---
  -  name: Download file
     s3: 
       profile: update
       region:  eu-west-2
       bucket: leases
       object: /{{item}}
       dest: /etc/downlds/{{ item }}
       mode: get    
     with_items: 
         - "{{ item1}}"
         - "{{ item2}}"

     register: downloads
     delegate_to: localhost 
     tags: download items

当我从控制台运行上面的剧本时它工作正常,在jenkins管道中我有这个

node {
    ansiblePlaybook installation: 'Ansible', playbook: '/home/ec2-user/Playbooks/copyfile.yml'
}

当我运行管道作业时,我收到如下错误

[tests] $ /usr/local/bin/ansible-playbook /home/ec2-user/Playbooks/copyfile.yml
FATAL: command execution failed
java.io.IOException: Process working directory '/var/lib/jenkins/workspace/tests' doesn't exist!
    at hudson.Proc$LocalProc.<init>(Proc.java:247)
    at hudson.Proc$LocalProc.<init>(Proc.java:218)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:930)
    at hudson.Launcher$ProcStarter.start(Launcher.java:450)
    at hudson.Launcher$ProcStarter.join(Launcher.java:461)
    at org.jenkinsci.plugins.ansible.CLIRunner.execute(CLIRunner.java:49)
    at org.jenkinsci.plugins.ansible.AbstractAnsibleInvocation.execute(AbstractAnsibleInvocation.java:290)
    at org.jenkinsci.plugins.ansible.AnsiblePlaybookInvocation.execute(AnsiblePlaybookInvocation.java:31)
    at org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder.perform(AnsiblePlaybookBuilder.java:261)
    at org.jenkinsci.plugins.ansible.workflow.AnsiblePlaybookStep$AnsiblePlaybookExecution.run(AnsiblePlaybookStep.java:400)
    at org.jenkinsci.plugins.ansible.workflow.AnsiblePlaybookStep$AnsiblePlaybookExecution.run(AnsiblePlaybookStep.java:321)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
    at hudson.security.ACL.impersonate(ACL.java:260)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
    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:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

我使用jenkins ansible插件,任何帮助将不胜感激

0 个答案:

没有答案