Notice
Recent Posts
Recent Comments
«   2025/07   »
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 29 30 31
Archives
Today
Total
관리 메뉴

ITFragile

[Ansible] 04. WEB 로드밸런싱 본문

Project

[Ansible] 04. WEB 로드밸런싱

경요 2023. 3. 16. 11:51

컨트롤노드에서 작성한 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>

웹서버로 옮길 index.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