当前位置: 首页 > news >正文

通过 Ansible 在 Windows 2022 上安装 IIS Web 服务器

拓扑结构

这是一个用于通过 Ansible 部署 IIS Web 服务器的实验室拓扑。

前提条件:

  •  在被管理的节点上安装WinRm
  •  准备一张自签名的证书
  •  开放防火墙入站tcp 5985 5986端口

准备自签名证书 

PS C:\Users\azureuser> $cert = New-SelfSignedCertificate -DnsName "solarwinds" -CertStoreLocation Cert:\LocalMachine\My
PS C:\Users\azureuser> $cert.Thumbprint
625D9DA3410A9F3FC87D853EA9730B5A8935F150

 

注册https listener,并绑定证书 

PS C:\Users\azureuser> winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="solarwinds"; CertificateThumbprint="625D9DA3410A9F3FC87D853EA9730B5A8935F150"}'

 验证https listener

PS C:\Users\azureuser> WinRM e winrm/config/listener

 定义ansible inventory file 

[windows_servers]
solarwinds ansible_host=20.47.126.72 ansible_connection=winrm ansible_winrm_transport=ntlm ansible_user=azureuser ansible_password=<yourpassword> ansible_winrm_connection_timeout=60[windows_servers:vars]
ansible_winrm_port=5986

创建ansible playbook

---
- name: Windows Featurehosts: solarwindsgather_facts: truetasks:- name: Disable Windows Updates Servicewin_service:name: wuauservstate: stoppedstart_mode: disabled- name: Run ipconfig and return IP address information.raw: ipconfigregister: ipconfig- debug: var=ipconfig# Install and enable IIS on Windows server 2019- name: Install IISwin_feature:name: "Web-Server"state: presentrestart: yesinclude_sub_features: yesinclude_management_tools: yes
# Copy the index.html file and rename to ansible.html under C:\inetpub\wwwroot. Must use \\ instead of \ for accessing directory on Windows server.- name: Copy index text pagewin_copy:src: "files/index.html"dest: "C:\\inetpub\\wwwroot\\ansible.html"

创建index.html文件

<html>
<head><title>Rock Ansible</title> 
</head>
<body><h1 style="background-color:DodgerBlue;"> Use Ansible to install and configure IIS on WIndows 2022</h1> <h3 style="color:Tomato;"> Welcome to Rock's Ansbile Test Page</h3>
</body>
</html>

运行ansible 命令来验证到windows server的链接

(base) ninjamac@ninjamacdeMacBook-Air ansible % ansible -i host1 windows_servers -m win_ping solarwinds | UNREACHABLE! => {"changed": false,"msg": "ntlm: HTTPSConnectionPool(host='20.47.126.72', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1006)')))","unreachable": true
}

该错误是自签名证书无法被macos信任导致,可以通过加上参数ansible_winrm_server_cert_validation=ignore来解决。

ansible -i host1 windows_servers -m setup -e ansible_winrm_server_cert_validation=ignore 

 

运行ansible playbook

 

 访问服务器的主页

相关文章:

  • IT学习方法与资料分享
  • Windows 下搭建 Zephyr 开发环境
  • VSCode CUDA C++进行Linux远程开发
  • 无法与IP建立连接,未能下载VSCode服务器
  • Redis线程安全深度解析:单线程模型的并发智慧
  • python学习打卡day47
  • PCDF (Progressive Continuous Discrimination Filter)模块构建
  • 基于深度学习的金枪鱼各类别目标检测含完整数据集
  • 如何配置 MySQL 允许远程连接
  • 从内存角度透视现代C++关键特性
  • 一些因子的解释
  • Python控制台输出彩色字体指南
  • Playwright自动化测试全栈指南:从基础到企业级实践(2025终极版)
  • Redis :String类型
  • iOS 门店营收表格功能的实现
  • 《Vuejs设计与实现》第 8 章(挂载与更新)
  • SUSE Linux 发行版全面解析:从开源先驱到企业级支柱
  • 青少年编程与数学 01-011 系统软件简介 07 iOS操作系统
  • Srping Cloud Gateway 跨域配置 CorsWebFilter
  • # 主流大语言模型安全性测试(二):英文越狱提示词下的表现与分析
  • 成都制作网站/网站排行榜查询
  • 京东网站建设需求分析报告/关于友谊的连接
  • 网站功能详细设计/东莞网站建设方案报价
  • 网站搭建公司排行榜/站内推广有哪些方式
  • wordpress后台500错误/seo排名优化首页
  • 做网站之前需要准备什么条件/苏州网站制作