Ansible Windows批量安装软件

文章目录

  • 1:Windows配置WINRM
  • [2: ansible安装](#2: ansible安装)
  • 3:操作步骤
    • [3.1 配置主机清单](#3.1 配置主机清单)
    • [3.2 测试ansible执行命令](#3.2 测试ansible执行命令)
    • [3.3 测试安装7Z](#3.3 测试安装7Z)

ansible操作通过winrm协议windows,经过实践精简以下方法能快速配置,并能通过测试

更多文档参考:

1:Windows配置WINRM

系统版本win10

以管理员权限运行Poweshell执行如下命令

powershell 复制代码
# 允许执行Powershell脚本
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
# 开启winrm
winrm quickconfig -force
# 配置winrm允许CredSSP方式认证
Enable-WSManCredSSP -Role Server -Force
# 测试winrm连接是否正常
winrs -r:http://localhost:5985/wsman -u:用户名(域用户填写xxxx@yyyy完整的UserPrincipalName) -p:密码 ipconfig

结果如下

2: ansible安装

系统环境:

  • ubuntu
  • python3
bash 复制代码
# 安装ansible
python3 -m pip install --user ansible
# 安装pywinrm[credssp]认证模块
pip install pywinrm[credssp]

3:操作步骤

3.1 配置主机清单

inventory.ini

ini 复制代码
[win]
172.25.1.9

[win:vars]
# ansible_user=用户名(域用户填写xxxx@yyyy完整的UserPrincipalName)
ansible_user=Administrator
ansible_password=123456
ansible_connection=winrm
ansible_winrm_transport=credssp
ansible_winrm_port=5985

3.2 测试ansible执行命令

bash 复制代码
# 执行命令
ansible -i inventory.ini win -m win_shell -a 'ipconfig'	

结果如下:

3.3 测试安装7Z

整体文件目录

编写playbook文件 install-7z.yaml

yaml 复制代码
- name: install 7z
  hosts: win

  tasks:
    - name: '下载7z安装包'
      ansible.windows.win_copy:
          src: /ansible-tutorial/7z1900-x64.msi
          dest: c:\7z1900-x64.msi

    - name: '安装msi'
      win_package:
        path: c:\7z1900-x64.msi
        state: present

执行命令,安装7z

bash 复制代码
# 安装7z
ansible-playbook -i inventory.ini install-7z.yaml
相关推荐
Boop_wu22 分钟前
[LangGraph] 案例 2 : 支持搜索的智能代理系统
服务器·windows·python·langchain
啦啦啦~~~2221 小时前
PC端+安卓端阅读器推荐!开源本地小说阅读器软件,
android·论文阅读·windows·开源软件·福昕阅读器
C++ 老炮儿的技术栈2 小时前
Qt5 使用 QPainter 绘制阿基米德螺线
开发语言·c++·windows·qt·代码化
今日热点3 小时前
Windows 系统 C 盘深度清理教程:安全释放存储空间,避开误删风险
windows·安全
gsls2008084 小时前
告别 Vault 的复杂度:用 Go 标准库给 Windows 凭据管理器装上 MCP
windows·golang·mcp
Mrs_DongDong4 小时前
华为云 Windows 服务器远程桌面自定义端口排障指南
服务器·windows·华为云
Sagittarius_A*4 小时前
CVE-2026-42271:从 MCP stdio 测试接口看 LiteLLM 的命令执行风险与防御闭环
网络·windows·安全·cve·rce
水饺编程4 小时前
第5章,[Win32 章节] :圆角矩形教学插图绘制程序
c语言·c++·windows·visual studio
公子小六18 小时前
基于.NET的Windows窗体编程之WinForms滑块与上下控件
windows·microsoft·c#·.net·winforms
学海浪太大1 天前
笔记本电脑插入显示器没反应
windows