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

Ansible Tower Plugin does not pass credentials from job to Ansible tower 3.6.1

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • ansible-tower-plugin
    • None
    • CloudBees Jenkins : 1.11.22
      Managed Master Version: 2.176.4
    • 0.14.0

      Jenkins job is not passing credentials to job template in Tower for Ansible tower version 3.6.1. 

      This used to work with Tower version 2.9

          [JENKINS-60352] Ansible Tower Plugin does not pass credentials from job to Ansible tower 3.6.1

          Lili Wang added a comment -

          Hi ALL,

           

          I find the issue,

           

          issue is in the source code: ../ansible-tower-plugin/src/main/java/org/jenkinsci/plugins/ansible_tower/util/TowerConnector.java

           

           

          Line:517

           

          Before Change

          // We need to pass individual fields
          if(credentials.get("machine").size() > 0) { postBody.put("credential", credentials.get("machine").get(0)); }
          if(credentials.get("vault").size() > 0) { postBody.put("vault_credential", credentials.get("vault").get(0)); }

           

          After Change:
                     // We need to pass individual fields
                      if(credentials.get("machine").size() > 0) { postBody.put("credentials", credentials.get("machine")); }
                      if(credentials.get("vault").size() > 0) { postBody.put("vault_credential", credentials.get("vault")); }
           

           

          Then it should works.

           

          Thank you.

           

           

          Lili Wang added a comment - Hi ALL,   I find the issue,   issue is in the source code: ../ansible-tower-plugin/src/main/java/org/jenkinsci/plugins/ansible_tower/util/TowerConnector.java     Line:517   Before Change // We need to pass individual fields if(credentials.get("machine").size() > 0) { postBody.put("credential", credentials.get("machine").get(0)); } if(credentials.get("vault").size() > 0) { postBody.put("vault_credential", credentials.get("vault").get(0)); }   After Change:            // We need to pass individual fields             if(credentials.get("machine").size() > 0) { postBody.put("credentials", credentials.get("machine")); }             if(credentials.get("vault").size() > 0) { postBody.put("vault_credential", credentials.get("vault")); }     Then it should works.   Thank you.    

          kyle fattig added a comment - - edited

          clover1983 That was the change I tried initially, but 'credentials' takes a list while 'credential' takes an int so tower throws a type error. That's jist of the issue though - Tower 3.6 removed the 'credential' field which is what the plugin sends.

           

          Here's the smallest change I could make that seems to work for now. There's already logic in place to account for this, it just needs to be used. Note this will break compatibility with old versions of the API that don't support 'credentials' field. We built this code and are using it for now as a stop-gap since Tower 3.6 supports only 'credentials':
          https://github.com/jenkinsci/ansible-tower-plugin/compare/master...kfattig:master

           

          johnwestcottiv I believe this code segment needs to be revisited. The comment explains the logic, but I believe it's flawed. Tower only accepts 1 machine credential currently, so the 'if' statement is never entered. Since the accepted fields change based on the API version - maybe that should be taken into account here instead?

           

          Happy to contribute or test as necessary, just didn't feel confident submitting a full PR without more information & testing.

          kyle fattig added a comment - - edited clover1983 That was the change I tried initially, but 'credentials' takes a list while 'credential' takes an int so tower throws a type error. That's jist of the issue though - Tower 3.6 removed the 'credential' field which is what the plugin sends.   Here's the smallest change I could make that seems to work for now. There's already logic in place to account for this, it just needs to be used. Note this will break compatibility with old versions of the API that don't support 'credentials' field. We built this code and are using it for now as a stop-gap since Tower 3.6 supports only 'credentials': https://github.com/jenkinsci/ansible-tower-plugin/compare/master...kfattig:master   johnwestcottiv  I believe this code segment  needs to be revisited. The comment explains the logic, but I believe it's flawed. Tower only accepts 1 machine credential currently, so the 'if' statement is never entered. Since the accepted fields change based on the API version - maybe that should be taken into account here instead?   Happy to contribute or test as necessary, just didn't feel confident submitting a full PR without more information & testing.

          John Westcott added a comment -

          Please reopen the ticket if the latest release does not resolve this issue.

          John Westcott added a comment - Please reopen the ticket if the latest release does not resolve this issue.

          Hi,

          This patch cause a NullPointerException (with AWX) because towerVersion attribute is apparently not properly filled.

          Cheers

          java.lang.NullPointerException
          	at org.jenkinsci.plugins.ansible_tower.util.TowerConnector.processCredentials(TowerConnector.java:518)
          	at org.jenkinsci.plugins.ansible_tower.util.TowerConnector.submitTemplate(TowerConnector.java:564)
          	at org.jenkinsci.plugins.ansible_tower.AnsibleTowerRunner.runJobTemplate(AnsibleTowerRunner.java:184)
          	at org.jenkinsci.plugins.ansible_tower.AnsibleTowerStep$AnsibleTowerStepExecution.run(AnsibleTowerStep.java:266)
          	at org.jenkinsci.plugins.ansible_tower.AnsibleTowerStep$AnsibleTowerStepExecution.run(AnsibleTowerStep.java:202)
          

          Frederic Leroux added a comment - Hi, This patch cause a NullPointerException (with AWX) because towerVersion attribute is apparently not properly filled. Cheers java.lang.NullPointerException at org.jenkinsci.plugins.ansible_tower.util.TowerConnector.processCredentials(TowerConnector.java:518) at org.jenkinsci.plugins.ansible_tower.util.TowerConnector.submitTemplate(TowerConnector.java:564) at org.jenkinsci.plugins.ansible_tower.AnsibleTowerRunner.runJobTemplate(AnsibleTowerRunner.java:184) at org.jenkinsci.plugins.ansible_tower.AnsibleTowerStep$AnsibleTowerStepExecution.run(AnsibleTowerStep.java:266) at org.jenkinsci.plugins.ansible_tower.AnsibleTowerStep$AnsibleTowerStepExecution.run(AnsibleTowerStep.java:202)

          John Westcott added a comment -

          Thanks you for the details, I believe I know what is going on now and am working on a fix. I'll let you know when that has been pushed and is ready for testing. Hopefully that will be later today.

          John Westcott added a comment - Thanks you for the details, I believe I know what is going on now and am working on a fix. I'll let you know when that has been pushed and is ready for testing. Hopefully that will be later today.

          John Westcott added a comment -

          This appears to have been an issue specifically with AWX v8.0.0 which reported its version as 8.0.0.0 (a 4 part notation instead of a three part notation). Jenkins 0.14.1 has been released which should hopefully address this scenario. It may take a couple days to be available for download. Please test and let me know if this now works. 

          John Westcott added a comment - This appears to have been an issue specifically with AWX v8.0.0 which reported its version as 8.0.0.0 (a 4 part notation instead of a three part notation). Jenkins 0.14.1 has been released which should hopefully address this scenario. It may take a couple days to be available for download. Please test and let me know if this now works. 

          Thanks for the feedback, I'll do the test in a couple of days and keep you posted

          Frederic Leroux added a comment - Thanks for the feedback, I'll do the test in a couple of days and keep you posted

            johnwestcottiv John Westcott
            vchebolu Viv Chebolu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: