Ansible管理windows2008
环境准备:
- 升级PowerShell到5.1版本及以以上(要先升级.Net Franmwork4.5)
- 开放5985端口
1.powershell远程连接配置
set-executionpolicy remotesigned
winrm quickconfig -q -force
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm enumerate winrm/config/listener
2.ansible连接windows配置
[win2008]
11.11.1.36
11.11.1.37
[win2008:vars]
ansible_ssh_port=5985
ansible_connection="winrm"
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport="ntlm"
#ansible_winrm_transport="basic"
ansible_ssh_user="vagrant"
ansible_ssh_pass="vagrant"
3.pscx模块安装
[pscx配置教程] https://www.cnblogs.com/kingleft/p/6444125.html
[pscx下载地址] https://psg-prod-eastus.azureedge.net/packages/pscx.3.3.2.nupkg
wget https://psg-prod-eastus.azureedge.net/packages/pscx.3.3.2.nupkg
mv pscx.3.3.2.nupkg pscx.3.3.2.zip
unzip pscx.3.3.2.zip -d pscx
4.软件安装(通过局域网共享安装)
- name: Install an EXE file
win_package:
path: \\192.168.0.245\run\npp.7.7.1.Installer.x64.exe
state: present
product_id: notepadd++
arguments: /S
become: yes
become_method: runas
become_flags: logon_type=new_credentials logon_flags=net_credentials_only
vars:
ansible_become_user: test
ansible_become_pass: tt
5.创建多个目录
- name: Create multi-directory
tags: create-multidir
win_shell: |
$value = Test-Path -Path {{item}}
if ($value -eq "true") {
echo {{item}} is exist !
}
else
{
New-Item -Path {{item}} -ItemType Directory
}
with_items:
- 'D:\website\iisbak'
- 'D:\website\working'
本文介绍了如何使用Ansible管理Windows 2008服务器,包括PowerShell远程连接配置、Ansible连接设置、安装PSCX模块以及通过局域网共享进行软件安装和创建多个目录的操作步骤。
776

被折叠的 条评论
为什么被折叠?



