Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use changed_when with ansible shell module?

Tags:

ansible

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?

like image 511
sorin Avatar asked May 23 '17 08:05

sorin


1 Answers

Yes, you can use registered variable. For example:

- shell: mycommand.sh
  register: script_res
  changed_when: "'changed' in script_res.stdout"
like image 194
Konstantin Suvorov Avatar answered Nov 15 '22 11:11

Konstantin Suvorov