- Here is a video tutorial
Scripts and configuration files are available
here:
- Install sshpass
SLES | openSUSE Leap 15.4
1
|
sudo zypper install sshpass
|
Debian
1
|
sudo apt install sshpass
|
Red Hat
1
|
sudo dnf install sshpass
|
- Install sudo on remote hosts
SLES | openSUSE Leap 15.4
1
|
sudo zypper install sudo
|
- Type the below command:
-
Change %sudo or %wheel to %admins
-
Add the below line:
1
|
%admins ALL=(ALL) NOPASSWD: ALL
|
Save and exit
- Add admins group
- Create a file on a master server where you will install ansible in the future
and place a password for the user that is currently able to connect to remote hosts.
- Make the script read only for this user
- Create a list of servers with IP addresses or hostnames
- Create a script
And add the below content
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#!/bin/bash
servers=$(cat servers)
echo -n "Enter the username: "
read userName
clear
for i in $servers; do
sshpass -f pass_file ssh -q -t $USER@$i "hostname; sudo usermod -aG admins $userName"
done
echo
read -n1 -s -p "Checking? (y)es or (n)o " ans
echo
if [ $ans == 'y' ] ;then
for i in $servers; do
sshpass -f pass_file ssh -q -t $USER@$i "hostname; id $userName"
done
fi
|
-
Make sure that PasswordAuthentication has set boolean value to yes in /etc/ssh/sshd_config file on remote servers
-
Make the script executable
1
|
chmod +x ansible-sudo.sh
|
- Execute the script
-
Provide username: ansible
-
See the result. User ansible should be added to group admins.