User Tools

Site Tools


docs:tips_n_tricks:ansible:shell.html

This is an old revision of the document!


Ansible - shell scripts

Task Template capable of check mode and reporting changed state

This template assumes, that “CHANGED” and “FAILED” are on a line by itself, which isn't true if some other part of the script had some output not delimited by a newline
roles/templates/tasks/shell1.yml
- name: You name it
  shell: |
    if echo "Fake check for need of change - always true"
    then
      echo 'CHANGED'
    fi
    if [ "False" == "{{ ansible_check_mode}}" ]
    then
      echo "Do the real thing here" || echo "FAILED" >&2
    fi
  check_mode: False
  register: my_result
  changed_when: 'CHANGED' in my_result.stdout_lines
  failed_when: 'FAILED' in my_result.stderr_lines

Ansible Shell

docs/tips_n_tricks/ansible/shell.html.1700916495.txt.gz · Last modified: 25.11.2023 13:48 CET by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki