Hi Team,

      I'm not able to execute ansible-playbook via plugin. When I hope in to the system found file is exist on the path tried to run same playbook manually from the same path it is working flawlessly.

      Please find the jenkins pipeline (plugin) logs below.

      [workspace] $ ansible-playbook clone-repo.yml -i inventory --private-key /Users/codiant/.jenkins/jobs/Sample-Node/workspace/ssh10574020522.key -u ubuntu
       FATAL: command execution failed
       java.io.IOException: Cannot run program "ansible-playbook" (in directory "/Users/rounak/.jenkins/jobs/Sample-Node/workspace"): error=2, No such file or directory
       at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
       at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
       at hudson.Proc$LocalProc.<init>(Proc.java:252)
       at hudson.Proc$LocalProc.<init>(Proc.java:221)
       at hudson.Launcher$LocalLauncher.launch(Launcher.java:995)
       at hudson.Launcher$ProcStarter.start(Launcher.java:507)
       at hudson.Launcher$ProcStarter.join(Launcher.java:518)
       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:430)
       at org.jenkinsci.plugins.ansible.workflow.AnsiblePlaybookStep$AnsiblePlaybookExecution.run(AnsiblePlaybookStep.java:351)
       at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
       at hudson.security.ACL.impersonate2(ACL.java:449)
       at hudson.security.ACL.impersonate(ACL.java:461)
       at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
       at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
       at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
       at java.base/java.lang.Thread.run(Thread.java:829)
       Caused by: java.io.IOException: error=2, No such file or directory
       at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
       at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
       at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
       at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)

          [JENKINS-67209] Cannot run program ansible-playbook

          I have run into this same problem.

          Plugin version: 1.1

          Jenkins version: 2.321

          OS: Oracle Linux 7

          I did go into the jenkins user shell and was able to access 'ansible' and 'ansible-playbook' which I believe means they are in the jenkins user PATH. That was my first suspicion for the error but now I am at a loss. 
          This worked before when ansible was installed with yum, which caused ansible to use Python 2.7. I reinstalled ansible using pip so that it would use Python 3. That changed caused this error. 

          Travis McElroy added a comment - I have run into this same problem. Plugin version: 1.1 Jenkins version: 2.321 OS: Oracle Linux 7 I did go into the jenkins user shell and was able to access 'ansible' and 'ansible-playbook' which I believe means they are in the jenkins user PATH. That was my first suspicion for the error but now I am at a loss.  This worked before when ansible was installed with yum, which caused ansible to use Python 2.7. I reinstalled ansible using pip so that it would use Python 3. That changed caused this error. 

          I was never able to solve why jenkins could not find Ansible in the path. However, I solved this by defining the Ansible location in "Global Tool Configuration". You can specify the folder with the Ansible executables with a name. 

          Then in the groovy script, you need a new parameter to call the installation. In my example, I named the executable location "ansible". The "installation" line tells the Ansible plugin to use the installation location.

          ansiblePlaybook(
          playbook: DYNAMIC_PLAYBOOK,
          inventory: INVENTORY_FILE,
          installation: 'ansible',
          )

          Travis McElroy added a comment - I was never able to solve why jenkins could not find Ansible in the path. However, I solved this by defining the Ansible location in "Global Tool Configuration". You can specify the folder with the Ansible executables with a name.  Then in the groovy script, you need a new parameter to call the installation. In my example, I named the executable location "ansible". The "installation" line tells the Ansible plugin to use the installation location. ansiblePlaybook( playbook: DYNAMIC_PLAYBOOK, inventory: INVENTORY_FILE, installation: 'ansible', )

          Torsten Krah added a comment -

          Thanks travis_mcelroy for mentioning the installation variant - still have the same problem in 2023 with the path one and via installation configuration it works.

          Torsten Krah added a comment - Thanks travis_mcelroy for mentioning the installation variant - still have the same problem in 2023 with the path one and via installation configuration it works.

            sirot Jean-Christophe Sirot
            rouna_cod Rounak Jain
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: