docs:tips_n_tricks:ansible:shell.html
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
docs:tips_n_tricks:ansible:shell.html [25.11.2023 15:22 CET] – peter | docs: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 | + | ===== Task template |
<note tip>This template assumes, that " | <note tip>This template assumes, that " | ||
<code yaml roles/ | <code yaml roles/ | ||
- | - 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 17: | Line 17: | ||
changed_when: | changed_when: | ||
failed_when: | failed_when: | ||
+ | </ | ||
+ | ===== 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 | ||
+ | <code yaml roles/ | ||
+ | - name: Collect information | ||
+ | shell: | | ||
+ | echo ' | ||
+ | check_mode: False | ||
+ | register: last_result | ||
+ | changed_when: | ||
+ | failed_when: | ||
+ | |||
+ | - name: Add to list if name does not exist | ||
+ | set_fact: | ||
+ | list_of_information: | ||
+ | loop: "{{ last_result.stdout_lines | from_json }}" | ||
+ | when: " | ||
</ | </ | ||
{{tag> | {{tag> | ||
{{entry> | {{entry> | ||
{{entry> | {{entry> |
docs/tips_n_tricks/ansible/shell.html.1700922137.txt.gz · Last modified: 25.11.2023 15:22 CET by peter