【问题标题】:Ansible: Wait until timeAnsible:等到时间
【发布时间】:2021-10-06 12:48:08
【问题描述】:

我需要一些有关 ansible-playbook 的帮助。 情况: 我们需要对某些开发系统进行不定期更新。对于我们的应用程序,一些大文件必须通过网络发送。为了不冒日常工作周期的风险,我们希望在晚上的特定时间使用 ansible 来执行此操作(如果需要)。

问题是:命令能否暂停脚本直到达到定义的时间(不使用 AWX 常规计划)? 谁能举个例子说明如何使用现有机制?

提前致谢

【问题讨论】:

    标签: ansible ansible-awx


    【解决方案1】:

    你的意思是这样的吗?

    - name: Sleep for 60 seconds and continue with play
      wait_for:
       timeout: 60
    

    【讨论】:

    • 嗨。更像。 - name: Wait until 6:25 AM pause: stop: 06:25:00.000000
    【解决方案2】:

    那么,你可能需要这样的东西。这是前一种方法的扩展。

    - hosts: localhost
      vars:
       var_wait_time: "18:25:00"
       var_wait_datetime: "{{ ansible_date_time.year }}-{{ ansible_date_time.month }}-{{ ansible_date_time.day }} {{ var_wait_time }}"
       var_current_datetime: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}"
      tasks:
      - name: "Calcualte the seconds to pause the play."
        set_fact:
         var_wait_seconds: "{{ ((var_wait_datetime | to_datetime) - (var_current_datetime | to_datetime)).total_seconds() }}"
        delegate_to: localhost
      - name: "Show the datetimes and seconds to play the pause."
        debug:
         msg: "{{ var_wait_datetime }} :: {{ var_current_datetime }} :: {{ var_wait_seconds }}"
        delegate_to: localhost
      - name: "Pause the play for {{ var_wait_seconds }} seconds."
        wait_for:
         timeout: "{{ var_wait_seconds }}"
        when: var_wait_seconds | int  > 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      相关资源
      最近更新 更多