• ansible控制winserver笔记


    原文地址: https://www.cnblogs.com/kingleft/p/6391652.html

    环境描述:

    ansible控制远程windows
    1.系统必须是sp1
    2.安装framework 3.0+
    3.升级powershell 3.0+
    4.开启winrm
    5.需要管理员密码、并且客户机不能安装安全卫士等相关软件

    1.管理机

    (1). 对管理主机的要求
    
    目前,只要机器上安装了 Python 2.6 或 Python 2.7 (windows系统不可以做控制主机),都可以运行Ansible.
    
    主机的系统可以是 Red Hat, Debian, CentOS, OS X, BSD的各种版本,等等.
    
    2)安装ansible
    yum install -y ansible
    
    3)python安装相关模块
    easy_install pip
    pip install paramiko PyYAML Jinja2 httplib2 six pywinrm
    
    (4)配置hosts文件:
    [windows]
    192.168.1.105 ansible_ssh_user="Administrator" ansible_ssh_pass="123456" ansible_ssh_port=5985 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore ansible_winrm_transport=ntlm
    
    至此,服务端配置完毕

     2.客户端

    所有安装包:H:sharesrcwinserver
    (5
    )Windows系统配置 和Linux发版版稍有区别,远程主机系统如为Windows需预先如下配置: 安装Framework 3.0+ 更改powershell策略为remotesigned 升级PowerShell至3.0+ 设置Windows远端管理,英文全称WS-Management(WinRM) 系统必须是SP1 如果不是需要打sp1补丁安装(windows6.1-KB976932-X64.exe) 目录H:sharesrcwinserver 5.1 安装Framework 3.0+ 下载链接为:http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_x86_x64.exe。 下载至本地后双击左键安装即可,期间可能会多次重启,电脑需正常连接Internet 5.2更改powershell策略为remotesigned set-executionpolicy remotesigned #powershell执行 必须要管理员运行 输入y get-executionpolicy #查看是否策略修改是否成功 5.3升级PowerShell至3.0+ Window 7和Windows Server 2008 R2默认安装的有PowerShell,但版本号一般为2.0版本,所以我们需升级至3.0+ get-host #查看版本 #执行upgrade_to_ps3.ps1 复制upgrade_to_ps3.ps1到桌面 右键powershell执行,执行完后重启系统 5.4 设置Windows远端管理(WS-Management,WinRM) [备注,window10默认powershell就是5.0+ 只要执行这里的和5.2更改powershell策略就行] powershell下执行以下: winrm enumerate winrm/config/listener #winrm service 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动
    ##网络需要设置专用网络 winrm quickconfig #针对winrm service 进行基础配置 输入两次:y 回去 winrm e winrm
    /config/listener #查看winrm service listener winrm set winrm/config/service/auth '@{Basic="true"}' #为winrm service 配置auth winrm set winrm/config/service '@{AllowUnencrypted="true"}' #为winrm service 配置加密方式为允许非加密
    winrm set winrm/config '@{MaxEnvelopeSizekb="1500"}'
    winrm set winrm/config '@{MaxTimeoutms ="60000"}'
    好了,远程Windows主机配置到此结束,我们验证配置的是否有问题
    更多winrm配置: https://www.cnblogs.com/weloveshare/p/5753139.html

     3.测试

    ansible windows -m win_ping   #win_ping —Windows系统下的ping模块,常用来测试主机是否存活
    
    ansible windows -m raw -a "shutdown -s -t 0"    #关机,执行cmd命令 (需要关闭360安全卫士)

    ansible windows -m raw -a "shutdown -r -t 0"    #关机,执行cmd命令 (需要关闭360安全卫士)
  • 相关阅读:
    PAT 1017 Queueing at Bank
    一句有意思的代码
    PAT 1031 Hello World for U
    PAT 1024 Palindromic Number
    PAT 1032 Sharing
    各显神通
    ZJU PAT 1023
    静夜,乱思
    PAT 1024 Palindromic Number
    虚函数表
  • 原文地址:https://www.cnblogs.com/hanxiaohui/p/9383903.html
Copyright © 2020-2023  润新知