Among Us - Yellow Crewmate [Ansible] Ansible 개념 정리 및 설치

DevOps/Ansible

[Ansible] Ansible 개념 정리 및 설치

감쟈! 2021. 4. 24. 20:06

1. Ansible ?

서버를 효율적으로 관리할 수 있게 해 주는 오픈 소스 IT 자동화 도구이다.

 

간혹 Ansible과 Terraform을 동일선상에서 보는 분들이 계시는데, Terraform과는 엄연히 다른 툴이고, 사용 목적이 다르다.

 

2. Ansible 특징

  • yaml 파일 형식으로 playbook 작성
  • Agentless - 별도의 Agent가 필요하지 않다
  • 멱등성을 가지고 있어서 여러번 수행하더라도 결과가 바뀌지 않는다.

 

3. Ansible 구성요소

 

1. Inventory (인벤토리)

 

Inventory 는 일반적으로 호스트를 정의한 파일을 의미한다.
호스트는 단독으로도 정의 할 수 있으며 그룹으로도 정의 가능하다.

# 인벤토리 작성 예제

[webservers]
localhost                    
web1.example.com
web2.example.com:1234       
192.168.0.100

[db-servers]
web1.example.com
db1.example.com

[servers:children]
webservers
db-servers

 

 

2. Playbook (플레이북)

Ansible에서 모듈을 호출하는 파일이며 Yaml 파일로 작성한다. Playbook은 Ansible의 핵심 요소이다.

 

# Playbook 작성 예제 (apache 설치)

- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest

 

 

 

4. Ansible 설치

AWS EC2 - Amazon linux2 에서 Ansible을 설치해보려고 한다.

Ansible은 Agent가 없기 때문에 설치하는 것은 매우 간단하다.

 

 

# Ansible 설치하기

$ amazon-linux-extras install ansible2 -y   # ansible 설치

$ ansible --version   # ansible 버전 확인