Skip to content

Commit

Permalink
Add ansible playbook for running commands on multiple hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Feb 13, 2024
1 parent 4b57693 commit 5fe8433
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ansible/see_command_output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# This is convenience function used for setting up servers, or troubleshooting.

- name: Run a command on all hosts, seeing the output
gather_facts: false

hosts:
# - all
- app1.thegreenwebfoundation.org
- app2.thegreenwebfoundation.org
- app3.thegreenwebfoundation.org
- app4.thegreenwebfoundation.org

remote_user: deploy
vars:
# a shell command defined here will be run on all the machines listed above
# the example below lists the available memory in human readable format
cli_command: "free -h"

tasks:
- name: "Run command as shell command"
# ansibile has other ways to run commands, see the command module as well
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html
ansible.builtin.shell:
cmd: "{{ cli_command }}"
become: false
register: output

- name: "See the output from stdout"
debug:
msg: "{{ output.stdout_lines }}"

0 comments on commit 5fe8433

Please sign in to comment.