Skip to main content
added 128 characters in body
Source Link

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible IMO although initial setup is more involved.

Short answer: Example updating and upgrading package with apt:

ansible myservers -a "sudo apt -y update" --become -K

ansible myservers -a "sudo apt -y upgrade" --become -K

Long answer and setup: For my situation, I was using MacOS locally to manage my remote Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created locally and on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though I'm unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your local machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your local machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove themthis user from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible IMO although initial setup is more involved.

Short answer: Example updating and upgrading package with apt:

ansible myservers -a "sudo apt -y update" --become -K

ansible myservers -a "sudo apt -y upgrade" --become -K

Long answer and setup: For my situation, I was using MacOS to manage my Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove them from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible IMO although initial setup is more involved.

Short answer: Example updating and upgrading package with apt:

ansible myservers -a "sudo apt -y update" --become -K

ansible myservers -a "sudo apt -y upgrade" --become -K

Long answer and setup: For my situation, I was using MacOS locally to manage my remote Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created locally and on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though I'm unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your local machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your local machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove this user from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.

added 128 characters in body
Source Link

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible IMO although theinitial setup is a bit more involved but once it is setup correctly its easy to use moving forward.

ForShort answer: Example updating and upgrading package with apt:

ansible myservers -a "sudo apt -y update" --become -K

ansible myservers -a "sudo apt -y upgrade" --become -K

Long answer and setup: For my situation, I was using MacOS to manage my Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove them from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible although the setup is a bit more involved but once it is setup correctly its easy to use moving forward.

For my situation, I was using MacOS to manage my Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove them from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible IMO although initial setup is more involved.

Short answer: Example updating and upgrading package with apt:

ansible myservers -a "sudo apt -y update" --become -K

ansible myservers -a "sudo apt -y upgrade" --become -K

Long answer and setup: For my situation, I was using MacOS to manage my Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove them from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.

Source Link

I agree with @satch_boogie comment above - use ansible when you need SUDO and use pssh when you don't - its cleaner to SUDO in ansible although the setup is a bit more involved but once it is setup correctly its easy to use moving forward.

For my situation, I was using MacOS to manage my Linux machines. I did the following which may vary slightly if your using Linux:

  1. make sure you have the same user created on all target machines: sudo adduser username
  2. add the user to the SUDO group on each target machine: usermod -aG sudo username
  3. (maybe optional) Setup passwordless ssh though unclear if this is needed but my environment was already setup with this. Try steps below first as it might not be necessary for passwordless ssh.
  4. Install ansible on your machine: brew install ansible (or linux sudo apt install ansible)
  5. create the default hosts file for ansible on your machine: sudo mkdir /etc/ansible && sudo touch /etc/ansible/hosts
  6. edit the file sudo nano /etc/ansible/hosts
  7. Add the target machines under a group (ip or machine name):
[myservers]
blah1.local
blah2.local
blah3.local
  1. (Optional) I had a second user in the SUDO group on all target machines so I had to temporarily remove them from the SUDO group to avoid a prompt (like when using sudo systemctl it asks to pick a SUDO user): ansible myservers -a "sudo deluser otheruser sudo" --become -K
  2. Now run the actual SUDO command you want. Example: ansible myservers -a "sudo apt -y update" --become -K
  3. (Optional) re-add the otheruser back to the SUDO group: ansible myservers -a "sudo adduser otheruser sudo" --become -K

Now every time I need to run a SUDO command across machines, I simply repeat steps 8-10.