title: How to make changed_when work in Ansible?
body: <p>I am trying to run a script using the command module on a Jenkins server. The script is written in such a way that it should return 0 if not making any configuration changes and the Ansible task should not be changed.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>  - name: Script to run
      command: java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 groovy "{{ jenkins_home }}/userContent/script.groovy"
      register: return_code
      changed_when: return_code.stdout != 0
  </code></pre>
  
  <p>But the above code behaves is always showing as changed.</p>
  
  <p>The Ansible output:</p>
  
  <blockquote>
    <p>TASK [jenkins : Script to run] ********************************</p>
    
    <p>changed: [test] => {"changed": true, "cmd": ["java", "-jar", "/var/cache/jenkins/war/WEB-INF/jenkins-cli.jar", "-s", "<a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a>", "groovy", "/var/lib/jenkins/userContent/script.groovy"], "delta": "0:00:01.547098", "end": "2017-02-06 15:31:05.989134", "rc": 0, "start": "2017-02-06 15:31:04.442036", "stderr": "[WARN] Failed to authenticate with your SSH keys. Proceeding as anonymous", "stdout": "0", "stdout_lines": ["0"], "warnings": []}</p>
  </blockquote>