Reputation: 191
What would be the best way to run commands in remote servers? I am thinking of using SSH, but is there a better way than that? I used Red Hat Linux and I want to run the command in one of the servers, specify what other servers I want to have my command run, and it has to do the exact same thing in the servers specified. Puppet couldn't solely help, but I might be able to combine some other tool with Puppet to do the job for me.
Upvotes: 0
Views: 731
Reputation: 160
It seems you are able to log on to the other servers without entering a password. I assume this is based on SSH keys, as described here: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-ssh-configuration-keypairs.html
You say another script is producing a list of servers. You can now use the following simple script to loop over the list:
for server in `./server-list-script`; do
echo $server:
ssh username@$server mkdir /etc/dir/test123
done >logfile 2>&1
The file "logfile" will collect the output. I'm pretty sure Puppet is able to do this as well.
Upvotes: 1
Reputation: 312858
Your solution will almost definitely end up involving ssh
in some capacity.
You may want something to help manage the execution of commands on multiple servers; ansible is a great choice for something like this.
For example, if I want to install libvirt
on a bunch of servers and make sure libvirtd
is running, I might pass a configuration like this to ansible-playbook
:
- hosts: all
tasks:
- yum:
name: libvirt
state: installed
- service:
name: libvirtd
state: running
enabled: true
This would ssh to all of the servers in my "inventory" (a file -- or command -- that provides ansible with a list of servers), install the libvirt
package, start libvirtd
, and then arrange for the service to start automatically at boot.
Alternatively, if I want to run puppet apply
on a bunch of servers, I could just use the ansible
command to run an ad-hoc command without requiring a configuration file:
ansible all -m command -a 'puppet apply'
Upvotes: 1