Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66357

Seed job that uses Job DSL to create new jobs, causes all jobs that use ansible plugin to be in a error state (Java.IO.Exception cannot run Ansible-Playbook)

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • Jenkins 2.289.2, Ansible Plugin 1.1, Job DSL 1.7, JCasC plugin 1.51, Uses jenkins configuration file to setup server, Ansible version 2.11.2, (also tried newest jenkins 2.3)

      We have been setting up a Jenkins development server and have been running into automation issues. Our current workflow is that we create a "Seed" job, which is a regular freestyle job in the UI, that serves to create all the rest of our jobs using the job DSL plugin. Therefore, this allows us to recreate our production server given that all our jobs from our production server are converted to groovy files. Once the seed job runs, it creates a bunch of new jobs which mimics our production server without having to create each job on its own. However, we are running into a problem when it comes to jobs that use the ansible plugin (which is the majority of the jobs). Upon trying to run these jobs we end up with the error: java.io.IOException: Cannot run program "ansible-playbook" as shown in the following photo. Through testing we managed to discover that upon opening the configuration of the job and making a change (i.e. checking and unchecking a boolean value or deleting a letter than re-adding a letter in textboxes) the job manages to execute successfully.  Once this state is fixed, then the issue does not come back. Our plan is to continuously run the seed job when we make changes to our groovy scripts, so our jobs can be updated without much work. However, every time we rerun the seed job we have this same error on the first run of each job until we use the solution as described above. (Note: we use a configuration file through the JCasC plugin so I was theorizing that this could create issues but potentially just a hunch)

          [JENKINS-66357] Seed job that uses Job DSL to create new jobs, causes all jobs that use ansible plugin to be in a error state (Java.IO.Exception cannot run Ansible-Playbook)

          Max added a comment -

          We seemed to have resolved this issue. You must specify the ansible version within the groovy scripts in order to prevent the jobs from failing. Adding the parameter i.e. ansibleName("Ansible-2.11.2") will resolve this issue. On pipeline scripts use the parameter "installation".

           

          Max added a comment - We seemed to have resolved this issue. You must specify the ansible version within the groovy scripts in order to prevent the jobs from failing. Adding the parameter i.e. ansibleName("Ansible-2.11.2") will resolve this issue. On pipeline scripts use the parameter "installation".  

          john added a comment -

          I am seeing this same failure behavior in pipelines wherein i am calling ansible playbooks. 
          pipeline {
          agent any
          environment

          { win_creds = credentials('jenkinswincreds') }

          stages {
          stage('winrm') {
          steps

          { ansiblePlaybook( playbook: '/data/ansible/ansiblemaster/winrm_prep.yml', inventory: '$jenkinsrawlist,', extras: '-e \"windows_username=$win_creds_USR windows_password=$win_creds_PSW ansible_username=$win_creds_USR\"', installation: "Ansible-2.11.3") }

          }

          Jenkins version 2.303.1

          Operating on ubuntu 20.04.

          Python 3.8.10

           

          Installation is all single machine, no nodes. Jenkins master is the jenkins node for now, and ansible runs on this same machine. Jenkins user account has been changed to run as the same user account as my in line ansible testing account "linux" for simplicity of permissions when testing key based authentication.   

           

          Adding the parameter specified by max did not alleviate this issue. 
          Thus far my only workaround has been manually creating the workspaces. 
          Which is rather painful in circumstances where I need to plan for multiple instances of the same job, i.e. this error: 
          FATAL: command execution failed
          java.io.IOException: Process working directory '/var/lib/jenkins/workspace/singlemachineenterprise@2' doesn't exist!
          For context the job is named singlemachineenterprise. One job is already running and i need to start another. @2 is automatically appended to the workspace. 

           

           

          john added a comment - I am seeing this same failure behavior in pipelines wherein i am calling ansible playbooks.  pipeline { agent any environment { win_creds = credentials('jenkinswincreds') } stages { stage('winrm') { steps { ansiblePlaybook( playbook: '/data/ansible/ansiblemaster/winrm_prep.yml', inventory: '$jenkinsrawlist,', extras: '-e \"windows_username=$win_creds_USR windows_password=$win_creds_PSW ansible_username=$win_creds_USR\"', installation: "Ansible-2.11.3") } } Jenkins version 2.303.1 Operating on ubuntu 20.04. Python 3.8.10   Installation is all single machine, no nodes. Jenkins master is the jenkins node for now, and ansible runs on this same machine. Jenkins user account has been changed to run as the same user account as my in line ansible testing account "linux" for simplicity of permissions when testing key based authentication.      Adding the parameter specified by max did not alleviate this issue.  Thus far my only workaround has been manually creating the workspaces.  Which is rather painful in circumstances where I need to plan for multiple instances of the same job, i.e. this error:  FATAL: command execution failed java.io.IOException: Process working directory '/var/lib/jenkins/workspace/singlemachineenterprise@2' doesn't exist! For context the job is named singlemachineenterprise. One job is already running and i need to start another. @2 is automatically appended to the workspace.     

            sirot Jean-Christophe Sirot
            mturek Max
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: