6

I have a complex shell script that is run by ansible and I do want to communicate from it to ansible when changes were made on the system, so Ansible will know that the host was modified.

This is achieve by using changed_when: condition but the problem is that I cannot really rely on a specific exit code to be used for success_with_change instead of success_without_change.

What other options are available? Can I use register: and use the registered variable inside changed_when: in order to check for a placeholder string in the output?

sorin
  • 161,544
  • 178
  • 535
  • 806

1 Answers1

10

Yes, you can use registered variable. For example:

- shell: mycommand.sh
  register: script_res
  changed_when: "'changed' in script_res.stdout"
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • The [Error Handling In Playbooks](https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#controlling-what-defines-failure) section in the Ansible documentation has more examples like that. Also for other cases such as `failed_when`, and `fail: msg=...` `when:`, which is pretty handy a lot of times. – Peterino Aug 30 '18 at 15:37