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
相关推荐
非凡ghost16 小时前
猫眼浏览器(Chrome内核增强版浏览器)官方便携版
前端·网络·chrome·windows·软件需求
熊文豪21 小时前
Windows安装RabbitMQ保姆级教程
windows·分布式·rabbitmq·安装rabbitmq
搬砖的小码农_Sky21 小时前
Windows操作系统上`ping`命令的用法详解
运维·网络·windows
Kiri霧1 天前
Rust模式匹配详解
开发语言·windows·rust
程序设计实验室1 天前
使用命令行删除 Windows 网络映射驱动器
windows
用户31187945592181 天前
Windows 电脑安装 XTerminal 1.25.1 x64 版(带安装包下载关键词)
windows
Logintern091 天前
windows如何设置mongodb的副本集
数据库·windows·mongodb
Chandler242 天前
一图掌握 操作系统 核心要点
linux·windows·后端·系统
ajassi20002 天前
开源 C# 快速开发(十七)进程--消息队列MSMQ
windows·开源·c#
Python私教2 天前
5分钟上手 MongoDB:从零安装到第一条数据插入(Windows / macOS / Linux 全平台图解)
windows·mongodb·macos