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

Some final output is missing in Jenkins Pipeline when using the Ansible Plugin

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When using the Ansible Plugin with jenkins Pipeline,
      I can't see the entire log on Jenkins PIpeline build output - Some output is missing at the end of the Ansible play.
      The output looks fine on a terminal - if I'll SSH to the server and run the ansible-playbook command from the command line.

      • This issue started about a month ago..

      Here is a screenshot of how the output look like now:
      https://imgur.com/waX7XcM

      Ansible Plugin:
      https://jenkins.io/doc/pipeline/steps/ansible/

      This is the Pipeline code that uses the Ansible Pipeline Plugin:

              stage('running something') {
                  steps {
                      script {
                          dir('my/path/here') {
                              ansiblePlaybook([
                                      inventory   : 'hosts',
                                      playbook    : 'main.yml',
                                      installation: 'ansible',
                                      sudoUser    : null,
                                      colorized   : true,
                                      extraVars   : [
                                              blah   : "${params.blah}",
                                              some_var       : "${params.some_var}"
                                      ]
                              ])
                          }
                      }
                  }
              }
      

        Attachments

          Issue Links

            Activity

            Hide
            svenxy Sven Hergenhahn added a comment - - edited

            Mee too. Since usually when a problem occurs, the output at the end is important, I've for now resorted to using ansible-playbook with sh 'ansible-playbook ...' in my pipeline and since have no problem with my output.

            I would prefer to return to the plugin though if possible

            Show
            svenxy Sven Hergenhahn added a comment - - edited Mee too. Since usually when a problem occurs, the output at the end is important, I've for now resorted to using ansible-playbook with sh 'ansible-playbook ...' in my pipeline and since have no problem with my output. I would prefer to return to the plugin though if possible
            Hide
            pablosan Pablo Sanchez added a comment -

            What I did to solve this, instead of manually calling Ansible from the Pipeline I extended the pipeline with a library method which calls Ansible.

            Something like:

            class Ansible implements IAnsible{    
                def context
                Map arguments    
                def ansiblePlaybook
                def ansibleInventory
                def ansibleExtras
                def ansibleExtraVars    
            
                Ansible(Map arguments, context){
                    this.context = context
                    this.arguments = arguments    
                }
            
                void parseArguments(Map arguments){
                    ansiblePlaybook = arguments.get("playbook", '')
                    ansibleInventory = arguments.get("inventory", '')
                    ansibleExtras = arguments.get("extras", '')
                    ansibleExtraVars = arguments.get("extraVars", '')
                }    
            
                String parseAnsibleExtraVars(Map extras){
                    def sb = new StringBuilder()        
                    sb.append('\'')
                    ansibleExtraVars.each(){ key, value ->
                        sb.append(key)
                        sb.append('=')
                        sb.append(value)
                        sb.append(' ')
                    }
                    sb.append('\'')        
                    return sb.toString()
                }    
            
                void playbookCall(){
                  parseArguments(this.arguments)        
                  def extraVars = parseAnsibleExtraVars(ansibleExtraVars)        
                  context.sh """ export ANSIBLE_FORCE_COLOR=1 \ 
                    && ansible-playbook -i ${ansibleInventory} ${ansiblePlaybook} --extra-vars ${extraVars}    ${ansibleExtras} """    
               }
            }
            

            And you call it pretty much in the same way from the pipeline, just create a method in vars:

            // code placeholder
            import com.ansible.Ansible
                    def call(Map ansibleParameters){
                        def ansibleRunner = new Ansible(ansibleParameters, this)
                        ansiColor('xterm') {
                            ansibleRunner.playbookCall()
                        }
                    }
            

             

             

            Show
            pablosan Pablo Sanchez added a comment - What I did to solve this, instead of manually calling Ansible from the Pipeline I extended the pipeline with a library method which calls Ansible. Something like: class Ansible implements IAnsible{ def context Map arguments def ansiblePlaybook def ansibleInventory def ansibleExtras def ansibleExtraVars Ansible(Map arguments, context){ this .context = context this .arguments = arguments } void parseArguments(Map arguments){ ansiblePlaybook = arguments.get( "playbook" , '') ansibleInventory = arguments.get( "inventory" , '') ansibleExtras = arguments.get( "extras" , '') ansibleExtraVars = arguments.get( "extraVars" , '') } String parseAnsibleExtraVars(Map extras){ def sb = new StringBuilder() sb.append( '\' ') ansibleExtraVars.each(){ key, value -> sb.append(key) sb.append( '=' ) sb.append(value) sb.append( ' ' ) } sb.append( '\' ') return sb.toString() } void playbookCall(){ parseArguments( this .arguments) def extraVars = parseAnsibleExtraVars(ansibleExtraVars) context.sh """ export ANSIBLE_FORCE_COLOR=1 \ && ansible-playbook -i ${ansibleInventory} ${ansiblePlaybook} --extra-vars ${extraVars} ${ansibleExtras} """ } } And you call it pretty much in the same way from the pipeline, just create a method in vars: // code placeholder import com.ansible.Ansible def call(Map ansibleParameters){ def ansibleRunner = new Ansible(ansibleParameters, this ) ansiColor( 'xterm' ) { ansibleRunner.playbookCall() } }    
            Hide
            stevendpclark Steven Clark added a comment - - edited

            I've submitted a PR that addresses this issue at least for me (https://github.com/jenkinsci/ansible-plugin/pull/29).Hopefully someone could accept it and create a bugfix release with it. 

             

            EDIT: Looks like there are a few different cases, the patch in that PR seemed to address at least one, but we are still seeing some trimmed output depending on how Ansible might have died from the looks of things. I'll keep on looking into the plugin but for now I've pulled the PR.

            Show
            stevendpclark Steven Clark added a comment - - edited I've submitted a PR that addresses this issue at least for me ( https://github.com/jenkinsci/ansible-plugin/pull/29 ).Hopefully someone could accept it and create a bugfix release with it.    EDIT:  Looks like there are a few different cases, the patch in that PR seemed to address at least one, but we are still seeing some trimmed output depending on how Ansible might have died from the looks of things. I'll keep on looking into the plugin but for now I've pulled the PR.
            Hide
            s777l Viacheslav Subotskyi added a comment -

            I had to switch to `sh` as well

            Show
            s777l Viacheslav Subotskyi added a comment - I had to switch to `sh` as well
            Hide
            stevendpclark Steven Clark added a comment -

            So we've been running with the latest PR (https://github.com/jenkinsci/ansible-plugin/pull/30) I created for the past two weeks and this new version of the PR seems to solve the issue.

             

            Is it possible to get the maintainer to look through the PR to get a new release of the plugin?

             

            Show
            stevendpclark Steven Clark added a comment - So we've been running with the latest PR ( https://github.com/jenkinsci/ansible-plugin/pull/30 ) I created for the past two weeks and this new version of the PR seems to solve the issue.   Is it possible to get the maintainer to look through the PR to get a new release of the plugin?  

              People

              • Assignee:
                sirot Jean-Christophe Sirot
                Reporter:
                nimitack Adam Delarosa
              • Votes:
                13 Vote for this issue
                Watchers:
                18 Start watching this issue

                Dates

                • Created:
                  Updated: