-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ansible playbook for running commands on multiple hosts
- Loading branch information
1 parent
4b57693
commit 5fe8433
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
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 }}" |