Thomas Brooks
Thomas Brooks

Reputation: 341

Ansible Playbook Fails when Executed Through Jenkins: /usr/bin/env: ‘python3’: No such file or directory

I wonder if someone encountered such issue:

When executing an Ansible playbook manually, on Ubuntu machine, everything works well. When executing the same playbook through Jenkins pipeline (in a configuration of Jenkins master on Windows, and agent on Ubuntu, with the relevant step executed on the Ubuntu agent) in the following way:

            stage ('Calling Ansible') {
                agent {
                    label 'ubuntu'
                }
                steps {
                    script {
                        ansiblePlaybook( 
                            playbook: '/home/jenkins/ansibleJenkins/test.yml'
                        )
                    }
                }
            }

I get the following error:

[lculator-jenkinsfile-test_master] $ ansible-playbook /home/jenkins/ansibleJenkins/test.yml
/usr/bin/env: ‘python3’: No such file or directory
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.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:367)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Note that when manually-checking in Ubuntu, when I execute:$ /usr/bin/env python3 --version I get: Python 3.8.2 in return.

Tried passing ansible_python_interpreter=/usr/bin/env python3 as extraVar in Jenkinsfile, but it didn't help.

Any help?

Upvotes: 0

Views: 2090

Answers (1)

Thomas Brooks
Thomas Brooks

Reputation: 341

Based on this answer on another topic, it turns out to be due to configuring "global path" in Jenkins master -> Configure System -> Global Properties, with path relevant to Windows. It prevented the Linux agent to use its own path.

Removing it solved the problem.

Upvotes: 2

Related Questions