windows的vars在hosts文件不生效,就寫了個腳本批量的添加hosts,懶的花時間找資料linux
政務雲每次推送主機都生成新的host inventory文件,模版密碼都同樣,ip存放list.txt文件windows
#!/bin/bash read -p "請輸入系統版本[windows/linux]: " version case $version in windows ) echo "[windows]" > /etc/ansible/hosts for ip in `cat list.txt` do echo "$ip ansible_ssh_user="Administrator" ansible_ssh_pass="模版密碼" ansible_ssh_port=5985 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore" >> /etc/ansible/hosts done echo "/etc/ansible/hosts文件建立成功" cat /etc/ansible/hosts ;; linux ) echo "[linux]" > /etc/ansible/hosts for ip in `cat list.txt` do echo "$ip ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='模版密碼'" >> /etc/ansible/hosts done echo "/etc/ansible/hosts文件建立成功" cat /etc/ansible/hosts ;; * ) echo "請輸入系統版本[windows/linux]" esac