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
相关推荐
Anesthesia丶2 分钟前
Windows WSL子系统设置独立IP访问
windows·网络协议·tcp/ip
Q168496451536 分钟前
k8s-通过ansible-playbook脚本将其他节点加入集群失败?
容器·kubernetes·ansible
weixin_531651811 小时前
Python 渐进式学习指南
开发语言·windows·python
夏日听雨眠1 小时前
文件学习终
windows·学习
无限进步_1 小时前
深入解析C++容器适配器:stack、queue与deque的实现与应用
linux·开发语言·c++·windows·git·github·visual studio
初圣魔门首席弟子1 小时前
bug2026.03.18
linux·服务器·windows
阿富软件园2 小时前
绿色便携免安装,双击即用零门槛排版预览一步到位照片排版工具
windows·电脑·开源软件
非凡ghost2 小时前
proDAD ReSpeedr:专业视频变速编辑的利器
java·网络·windows·python·音视频·软件需求
big tail3 小时前
Windows本地Docker模拟前端项目发版
前端·windows·docker
yuyu_03043 小时前
Spring Boot在Windows开机自启动
windows·spring boot·后端