使用ansible为Windows上的服务用户设置密码

问题描述 投票:0回答:1

我试图在Windows机器上使用ansible模块来设置现有服务的用户和密码。

模块链接: https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_service_module.html

  • name:设置登录用户为本地账户

    ansible.windows.win_service:

    名称:服务名称

    状态:重新启动

    用户名:.\my_user

    密码:SomePassword#1111

我的自定义用户已添加到管理员组。 完成此任务后,用户被设置为服务,但密码错误。 如果我尝试启动该服务,我登录失败,如果我手动粘贴相同的密码,它就可以工作。那么为什么相同的密码不能通过 Ansible 工作呢?

最诚挚的问候, 乌鸦。

windows automation ansible
1个回答
0
投票

我的用例是一个需要以登录用户身份运行的 .bat 脚本。这是我为使其发挥作用所做的工作。我使用 NSSM 创建了 win_service 模块的服务来更新密码。

  - name: Grant user right
    win_user_right:
      name: SeServiceLogonRight
      users:
        - "{{ my_user }}"
      action: add

  - name: create service with nssm
    win_nssm:
      name: my-service
      application: "test.bat"
      stderr_file: "error.log"

  - name: Set user
    win_service:
      name: my-service
      username: "{{ my_user }}"
      password: "{{ my_pass  }}"
      update_password: always
      state: started
© www.soinside.com 2019 - 2024. All rights reserved.