【问题标题】:Ansible win_scheduled_task how to start a task immediatelyAnsible win_scheduled_task 如何立即启动任务
【发布时间】:2021-01-08 09:46:50
【问题描述】:

请提供建议!

路径中有一个程序:

C:\Program Files(x86)\Common Files\Autodesk Shared\AdskLicensing\Current\helper\AdskLicensingInstHelper.exe

而且必须带参数运行:

register -pk 829L1 -pv 2020.0.0.F -cf "\\ srv\deploy$\RVT20\Img\x64\RVT\RevitConfig.pit" -el EN

我决定通过任务调度器来做,但在文档中没有找到添加后如何立即启动任务。

- name: recover ADSKLic Service
      win_scheduled_task:
        name: ADSK
        description: RecADSK
        actions:
        - path: 'C:\Program Files(x86)\Common Files\Autodesk Shared\AdskLicensing\Current\helper\AdskLicensingInstHelper.exe'
          arguments: register -pk 829L1 -pv 2020.0.0.F -cf "\\srv\deploy$\RVT20\Img\x64\RVT\RevitConfig.pit" -el EN
        triggers:
        - type: registration
        frequency: once
        state: present
        enabled: yes
        username: SYSTEM
      tags: rev, adsk, task

任务正在添加中,添加后如何立即启动?

通过win_commandraw 运行.exe 当然可能更容易 但这对我不起作用...

【问题讨论】:

    标签: windows ansible autodesk


    【解决方案1】:

    自己解决了..它有效。 添加、立即执行和删除任务

     - name: recover ADSKLic Service Trough task scheduler
          win_scheduled_task:
            name: ADSK
            username: SYSTEM
            actions:
            - path: 'C:\Program Files (x86)\Common Files\Autodesk Shared\AdskLicensing\Current\helper\AdskLicensingInstHelper.exe'
              arguments: register -pk 829L1 -pv 2020.0.0.F -cf "\\srv\deploy$\RVT20\Img\x64\RVT\RevitConfig.pit" -el EN
           # Remove this action if the task shouldn't be deleted on completion
            - path: cmd.exe
              arguments: /c schtasks.exe /Delete /TN "ADSK" /F
            triggers:
            - type: registration
          tags: task
        - name: Wait for the scheduled task to complete
          win_scheduled_task_stat:
            name: ADSK
            register: task_stat
            until: (task_stat.state is defined and task_stat.state.status != "TASK_STATE_RUNNING") or (task_stat.task_exists == False)
            retries: 7
            delay: 5
          tags: task 
    

    【讨论】:

    • 谢谢!我只是想说,所提供的代码需要稍作调整才能工作:在win_scheduled_task_stat: 部分,只有name: 应该缩进。 register:until:retries:delay: 应该被删除(与 win_scheduled_task_stat:tags: 处于同一级别),否则 Ansible 会抱怨。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2016-09-06
    • 2013-12-16
    • 2022-10-05
    • 2023-04-08
    • 2020-10-19
    相关资源
    最近更新 更多