본문 바로가기
인프라/앤서블(Ansible)

[ANSIBLE] 앤서블 윈도우 task timeout 설정하기

by IT맥구리나스 2023. 12. 11.

playbook내 각 윈도우 task가 있다고 가정하면 한 task가 실행한 후

10~20초정도 멈췄다가 다음 task를 수행해야할 때가 있다.

 

방법은 pause 모듈을 사용하면 된다.

   - name: pause
     pause:
       seconds: 40

 

 

아래 코드는 exec cmd 테스크가 실행된 후 pause 테스크를 통해 40초 쉬었다가 get list of running processes를

수행하는 플레이북이다.

---
- hosts: all
  gather_facts: no
  vars:
     ansible_connection: winrm
     ansible_winrm_server_cert_validation: ignore
     ansible_winrm_scheme: http
     ansible_become: false
     ansible_winrm_transport: basic
     ansible_port: 5985
  tasks:
   - name: exec cmd
     win_shell: "{{ cmd }}"

   - name: pause
     pause:
       seconds: 40

   - name: Get list of running processes
     win_shell: powershell -command "(Get-Process -Name 'test.exe' -ErrorAction SilentlyContinue).Count -gt 0"
     register: process_list
     ignore_errors: yes

   - name: Check if notepad.exe is running
     debug:
       msg: "process_list.stdout test.exe running status : {{ process_list.stdout }}"
반응형

댓글