일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 6억이하아파트
- Ansible
- pod
- 명령어
- EC2
- 서버간 파일전송
- 옥수삼성아파트
- 2025년정책
- describe-instances
- kubectl
- 9억이하
- 5호선
- 행당대림아파트
- 쿠버네티스
- ELB
- 신혼부부아파트
- Configmap
- statefulset
- k8s
- 행당역
- 답십리 파크자이
- React Native
- 황학동롯데캐슬
- aws cli
- 아파트
- 행당한진아파트
- 천호태영아파트
- 응봉현대아파트
- docker
- 미아뉴타운sk북한산아파트
- Today
- Total
게으름을 위한 부지런한 게으름뱅리' 블로그
[Ansible] wait_for 와 wait_for_connection 사용하기 본문
♬ wait_for 모듈
ansible(앤서블)의 wait_for 모듈은 특정 동작을 대기, 확인할 때 쓰이는 모듈입니다.
Application의 상태를 확인하거나, 파일의 존재여부를 확인, 파일의 특정 내용의 유무 등을 확인하여 다음 동작의 여부를 판단하는데 주로 사용하였습니다.
자세한 내용은 가이드 문서를 참고 부탁드립니다.
docs.ansible.com/ansible/2.3/wait_for_module.html
wait_for - Waits for a condition before continuing. — Ansible Documentation
You are reading an unmaintained version of the Ans
docs.ansible.com
♪ Application 관련 사용
(생략)
tasks:
- name: Waiting for application to start
wait_for:
port: "service port"
delay: "delay seconds"
- port : Application 실행 포트 ( check할 포트)
- delay : 입력한 숫자의 초만큼 지난 후 실행
♪ 파일 관련 사용
- 정규표현식에 맞는 값이 파일에서 나타나면 다음 스텝 진행
(생략)
tasks:
- name: check file
wait_for:
path: /path/to/file
search_regex: "정규표현식"
- wait_for : 체크할 파일의 경로
- search_regex: 정규표현식
- 파일이 생성되면 다음 스텝 진행
(생략)
tasks:
- name: check file
wait_for:
path: /path/to/file
- 파일이 삭제되면 다음 스텝 진행
(생략)
tasks:
- name: check file
wait_for:
path: /path/to/file
state: absent
♬ wait_for_connection 모듈
ansible(앤서블)의 wait_for_connection 모듈은 ansible playbook의 host에 접속이 될 때까지 대기하는 모듈입니다.
저는 AWS EC2 instance를 새로 생성하고 생성이 완료 될 때까지 wait_for_connection 모듈을 사용하여 체크 한 후 다음 스텝을 진행하였습니다.
자세한 내용은 가이드 문서를 참고 부탁드립니다.
docs.ansible.com/ansible/latest/collections/ansible/builtin/wait_for_connection_module.html
ansible.builtin.wait_for_connection – Waits until remote system is reachable/usable — Ansible Documentation
Note This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name wait_for_connection even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy
docs.ansible.com
- name: Checking if the server is started
hosts: "hostname"
gather_facts: false
remote_user: ubuntu
tasks:
- name: Check instance
wait_for_connection:
delay: "delay seconds"
timeout: "timeout seconds"
- hosts : 접속할 host명
- gather_facts : false로 설정 하면 host에 입력된 주소로 ping체크 비활성화, 이 옵션을 주지 않으면 접속 에러 발생.
- remote_user: 접속할 user
- wait_for_connection : 서버가 실행 될때까지 주기적으로 접속가능여부 체크 (defalut timeout은 600초)
- delay : 입력한 시간이 지나고 체크 실행 (단위는 초)
- timeout: timeout 설정(단위는 초)
- wait_for_connection default로 사용하려면 아래와 같이 delay와 timeout값을 입력하지 않고 사용하면 됩니다.
- name: Checking if the server is started
hosts: "hostname"
gather_facts: false
remote_user: ubuntu
tasks:
- name: Check instance
wait_for_connection:
'IT > Ansible' 카테고리의 다른 글
[Ansible] lineinfile 모듈을 사용하여 파일 수정하기 (0) | 2021.01.13 |
---|---|
[Ansible] fetch, copy 모듈을 사용하여 파일 복사하기 (0) | 2021.01.12 |
[Ansible] Synchronize 모듈을 사용하여 Remote to Remote 파일전송하기 (0) | 2020.12.18 |