Skip to content

Instantly share code, notes, and snippets.

@teramako
Created December 19, 2020 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teramako/d8ebc9c5a6ddaefdadd6d9348183261c to your computer and use it in GitHub Desktop.
Save teramako/d8ebc9c5a6ddaefdadd6d9348183261c to your computer and use it in GitHub Desktop.
ansible-playbook simple_cmds.yml -e @cmds.yml
## this is sample
COMMANDS:
- |
id
uname -n
date
- cat /path/to/file
ADMIN: true
- 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