windows的vars在hosts文件不生效,就写了个脚本批量的添加hosts,懒的花时间找资料

政务云每次推送主机都生成新的host inventory文件,模版密码都一样,ip存放list.txt文件

#!/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