Created
December 19, 2020 09:22
-
-
Save teramako/d8ebc9c5a6ddaefdadd6d9348183261c to your computer and use it in GitHub Desktop.
ansible-playbook simple_cmds.yml -e @cmds.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## this is sample | |
COMMANDS: | |
- | | |
id | |
uname -n | |
date | |
- cat /path/to/file | |
ADMIN: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Simple commands | |
hosts: all:!localhost | |
gather_facts: false | |
tasks: | |
- name: Show commands | |
debug: | |
var: COMMANDS | |
run_once: true | |
- name: Execute commands | |
shell: "{{ item }}" | |
args: | |
warn: false | |
register: SHELL | |
ignore_errors: true | |
when: SHELL is undefined or SHELL is success | |
loop: "{{ COMMANDS }}" | |
become: "{{ ADMIN|default(false) }}" | |
- name: Show results | |
debug: | |
msg: | |
- "Start: {{ item.start }}, End: {{ item.end }}" | |
- "RC: {{ item.rc }}" | |
- "{{ item.stdout_lines }}" | |
- "{{ item.stderr_lines }}" | |
when: item is not skipped | |
loop: "{{ SHELL.results }}" | |
loop_control: | |
label: "{{ item.cmd|default(item.item) }}" | |
# vim: set ft=yaml.ansible list: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment