User Tools

Site Tools


docs:tips_n_tricks:ansible:shell.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
docs:tips_n_tricks:ansible:shell.html [25.11.2023 15:36 CET] peterdocs:tips_n_tricks:ansible:shell.html [25.11.2023 15:45 CET] (current) peter
Line 1: Line 1:
 ====== Ansible - shell scripts ====== ====== Ansible - shell scripts ======
-===== Task Template capable of check mode and reporting changed state =====+===== Task template capable of check mode and reporting changed state =====
 <note tip>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</note> <note tip>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</note>
 <code yaml roles/templates/tasks/shell1.yml> <code yaml roles/templates/tasks/shell1.yml>
-- name: You name it+- name: Shell scriptlet
   shell: |   shell: |
     if echo "Fake check for need of change - always true"     if echo "Fake check for need of change - always true"
Line 18: Line 18:
   failed_when: "'FAILED' in my_result.stderr_lines"   failed_when: "'FAILED' in my_result.stderr_lines"
 </code> </code>
-===== Task Template executing always - even in check mode - and failing on any output to stderr =====+===== Task template executing always - even in check mode - and failing on any output to stderr =====
 This might be useful when using a script to gather information about the target host This might be useful when using a script to gather information about the target host
-<code yaml roles/templates/tasks/shell1.yml> +<code yaml roles/templates/tasks/shell2.yml> 
-- name: You name it+- name: Collect information
   shell: |   shell: |
-    echo '{"name": "Test", "msg": "Do the real thing here"}' || echo "FAILED" >&2+    echo '{"name": "Test", "msg": "Do the real thing here"}' ||  echo "FAILED" >&2
   check_mode: False   check_mode: False
   register: last_result   register: last_result
docs/tips_n_tricks/ansible/shell.html.txt · Last modified: 25.11.2023 15:45 CET by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki