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

通过 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

 

 访问服务器的主页

http://www.xdnf.cn/news/12508.html

相关文章:

  • Python 自定义函数详解及递归函数等案例
  • 协议哨兵:场景化协议风险的ai工具
  • Tableau for mac 驱动
  • 《探秘局域网广播:网络世界的 “大喇叭”》
  • 前端 Electron 桌面应用学习笔记
  • electron-vite串口通信
  • 队列的概念及实现
  • LeetCode 高频 SQL 50 题(基础版)之 【子查询】· 上
  • (LeetCode 每日一题)3170. 删除星号以后字典序最小的字符串(贪心+栈)
  • Vue3学习(4)- computed的使用
  • 【学习笔记】深度学习-参数初始化
  • Android 蓝牙通信
  • 从0开始学习R语言--Day19--连续变量的相关性检验
  • c++ 单例模式
  • Android和硬件通信
  • 二.单例模式‌
  • Shell: 解决文件复制后权限变化问题
  • 两阶段提交
  • 7.2.1_顺序查找
  • Linux 初始化与服务管理全解析:rc.d、systemctl与service对比
  • 我用AI降低AI率:一次“用魔法打败魔法”的实验
  • 深入理解 Python `asyncio` 的子进程协议(Subprocess Protocol)
  • 离散傅里叶级数(DFS)的用途
  • Qt生成日志与以及捕获崩溃文件(mingw64位,winDbg)————附带详细解说
  • DevSecOps新理念
  • 【信息系统项目管理师-选择真题】2025上半年(第二批)综合知识答案和详解(回忆版)
  • flex布局 flex:1里面的盒子内容过多溢出处理
  • FISCO-BCOS 联盟链 caliper测试示例非常完善
  • vxe-table 如何设置单元格垂直对齐
  • PP-OCRv5_server_det.yml参数解释