ITFragile
[Ansible] 04. WEB 로드밸런싱 본문
컨트롤노드에서 작성한 index.html을 web01,02에 로드밸런싱되게 옮기려고 함
1. main 플레이북 추가
2. index.html 작성
#controlnode
# vim index.html
<html>
<body>
<h1><font color="purple">
Welcome to Kyungeun's Page!!!
</font></h1>
</body>
</html>
3. 플레이북 작성
# index.yaml
- name: copy index.html
template:
src: index.html
dest: /var/www/html
- name: rewrite index.html
lineinfile: # 해당 경로의 파일 내용 변경
path: /var/www/html/index.html
regexp: "^Welcome"
line: Welcome to Kyungeun's Page!!! {{ ansible_facts.hostname }} # ansible facts 사용
이때 web01,02 로드밸런싱을 확인할 수 있도록 두 대의 서버에 각 호스트의 이름을 변수로 사용함
gathering facts 확인
ansible web-01 -m setup| more
"ansible_hostname": "web-01"
"ansible_hostname": "web-02"
4. 플레이북 실행 후 접속 확인
'Project' 카테고리의 다른 글
[Ansible] 06. mysql 구성하기 (0) | 2023.03.16 |
---|---|
[Ansible] 05. DB 이중화 (0) | 2023.03.16 |
[Ansible] 03. HAProxy 설정 (0) | 2023.03.16 |
[Ansible] 02. Playbook 작성 (0) | 2023.03.15 |
[Ansible] 01. 작업 환경 구성 (0) | 2023.03.15 |