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
相关推荐
渣渣灰95871 小时前
Windows11安装WSL2(Windows Subsystem for Linux)
linux·运维·windows
不绝1911 小时前
C#进阶:常用泛型数据结构类
windows
深念Y1 小时前
C盘根目录文件清理与C盘管理
windows·系统·清理·卸载·软件·c盘·垃圾
dgaf1 小时前
(2023-06-07) Win32API【1】-- DevC++做一个窗口
c++·windows·microsoft
钮钴禄·爱因斯晨1 小时前
操作系统第一章:计算机系统概述
linux·windows·ubuntu·系统架构·centos·鸿蒙系统·gnu
呉師傅14 小时前
东芝3525AC彩色复印机CC219测试页打印方法【实际操作】
运维·网络·windows·计算机外设·电脑
开开心心就好15 小时前
音频编辑工具,多端支持基础剪辑易操作
java·网络·windows·java-ee·电脑·maven·excel
季布,16 小时前
本地Windows测试:钉钉群消息/文件传输到Python服务(完整教程)
windows·python·钉钉
iAkuya18 小时前
(leetcode)力扣100 46二叉树展开为链表(递归||迭代||右子树的前置节点)
windows·leetcode·链表
海天鹰19 小时前
文件右键菜单删除转换为pdf格式
windows