Last active
May 14, 2019 18:57
-
-
Save fabriciorsf/9b96490544843967ac0ef8667f725d94 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# em cada PC remoto, logo após a instalação limpa do ubuntu desktop LTS | |
#ip a ## anotar o IP | |
#sudo apt install openssh-client openssh-server -y | |
# no PC administrador | |
if ! grep -q "^deb .*ansible" /etc/apt/sources.list /etc/apt/sources.list.d/*; then | |
sudo add-apt-repository ppa:ansible/ansible | |
sudo apt update | |
fi | |
sudo apt install ansible expect nmap -y | |
NET_IP="11.0.0." | |
HOST_USER="admindtl" | |
PASSWD="admin123" | |
FILE_HOSTS="hosts_labDTL" | |
HOSTS="lab-dtl" | |
LIST_IPS=$( sudo nmap -sS -p 22 --open "${NET_IP}0/24" | grep -oP "(?<=${NET_IP})[0-9]*" ) | |
echo "Scanned IPs: ${LIST_IPS}" | |
PASSPHRASE=$( LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 13 ; echo ) | |
#ssh-keygen -t rsa | |
./expect_ssh-keygen.sh ${PASSPHRASE} | |
echo "[${HOSTS}]" > ${FILE_HOSTS} | |
for FINAL_IP in ${LIST_IPS}; do | |
HOST_IP=${NET_IP}${FINAL_IP} | |
echo "configuring ${HOST_IP} ..." | |
#ssh-copy-id ${HOST_USER}@${HOST_IP} | |
./expect_ssh-copy.sh ${HOST_USER} ${HOST_IP} ${PASSWD} | |
echo "${HOST_IP}" >> ${FILE_HOSTS} | |
done | |
echo "ansible -i ${FILE_HOSTS} ${HOSTS} -m ping -u ${HOST_USER} -e 'ansible_python_interpreter=/usr/bin/python3'" | |
ansible -i ${FILE_HOSTS} ${HOSTS} -m ping -u ${HOST_USER} -e 'ansible_python_interpreter=/usr/bin/python3' | |
RESULT=$( ansible -i ${FILE_HOSTS} ${HOSTS} -m ping -u ${HOST_USER} -e 'ansible_python_interpreter=/usr/bin/python3' ) | |
LIST_VALID_IPS=$( echo $RESULT | grep -oP "[0-9]+.[0-9]+.[0-9]+.[0-9]+(?= \| SUCCESS)" ) | |
echo "Valid IPs: ${LIST_IPS}" | |
echo "[${HOSTS}]" > ${FILE_HOSTS} | |
for HOST_VALID_IP in ${LIST_VALID_IPS}; do | |
echo "${HOST_VALID_IP}" >> ${FILE_HOSTS} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment