(Ansible) 04. WEB 로드 밸런싱

제어 노드에 작성된 index.html을 로드 밸런서의 web01,02로 이동해 봅니다.

1. 메인 스크립트 늘리기


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의 로드밸런싱을 확인한다.

확인 수집 사실

ansible web-01 -m 설정 | 더보기


해당 부분을 변수로 사용할 수 있습니다.

“ansible_hostname”: “웹-01”

“ansible_hostname”: “웹-02”

4. 플레이북 실행 후 연결 확인




로드 밸런싱 정상