0% found this document useful (0 votes)
5 views1 page

Ansible Playbook To Run The Commands 4 Output in Singlefile

This document provides instructions for executing commands on multiple servers using Ansible. It includes placeholders for file paths, remote user credentials, and output storage locations. The playbook is structured to read commands from a file, execute them on specified servers, and store the output in designated files.

Uploaded by

afba2331
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Ansible Playbook To Run The Commands 4 Output in Singlefile

This document provides instructions for executing commands on multiple servers using Ansible. It includes placeholders for file paths, remote user credentials, and output storage locations. The playbook is structured to read commands from a file, execute them on specified servers, and store the output in designated files.

Uploaded by

afba2331
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

'''

Make sure to replace the following placeholders:

path/to/commands.txt: Replace this with the path to the file containing the list of
commands you want to run.
your_remote_user: Replace this with the username you use to log in to the remote
servers.
path/to/output/: Replace this with the desired path to store the output files.
You can run the playbook using the ansible-playbook command:

bash
Copy code
ansible-playbook -i path/to/inventory.ini playbook.yml
Replace path/to/inventory.ini with the path to your inventory file.

Ensure that you have Ansible installed and configured properly, and the inventory
file contains the server groups you want to target.

'''

---
- name: Execute commands on multiple servers
hosts: all
gather_facts: false

tasks:
- name: Read commands from file
slurp:
src: path/to/commands.txt
register: command_file

- name: Execute commands on servers


shell: "{{ item }}"
register: command_output
with_lines: "{{ command_file.content | b64decode | split('\n') }}"
remote_user: your_remote_user

- name: Store command output


copy:
content: "{{ item.stdout }}"
dest: path/to/output/{{ inventory_hostname }}.txt
with_items: "{{ command_output.results }}"

You might also like