ansible管理windows (发送文件)

https://github.com/ansible/ansible/raw/devel/examples/scripts/ConfigureRemotingForAnsible.ps1

环境:

服务器端

python2.7

centos7

ansible        yum install ansible

被管理windows端 win-server2012需要powershell 3.0 +开启winrm服务 +开启防火墙规则+配置powershell策略为remotesigned 

 一、python 依赖包安装

下载pip
#wget https://bootstrap.pypa.io/get-pip.py
#python get-pip.py
安装依赖
#pip install pywinrm paramiko PyYAML Jinja2 httplib2 six

 

二、hosts文件配置

vim  /etc/ansible/hosts

[windows]
47.107.24.1  ansible_winrm_transport=ntlm  ansible_ssh_user="Administrator" ansible_ssh_pass="123456" ansible_ssh_port=5985 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore

 

三、win 设置

# 创建目录
mkdir c:\ansible
cd c:\ansible

# 下载脚本
wget https://github.com/ansible/ansible/raw/devel/examples/scripts/ConfigureRemotingForAnsible.ps1

# 开启WinRM服务 set-ExecutionPolicy RemoteSigned

#开启防火墙端口
netsh advfirewall firewall add rule name="Win-RM-HTTP" dir=in localport=5985 protocol=TCP action=allow

 

四、执行命令发送文件

ansible "*"  -m win_copy -a  "src=/tmp/ansible_test dest=c:/ansible"

 

参考文档:https://www.jianshu.com/p/0ad50049adb7

转载于:https://www.cnblogs.com/kevincaptain/p/10131768.html

你可能感兴趣的:(ansible管理windows (发送文件))