[Ansible] 앤서블 학습 - 2. inventory(INI)

 

Invertory 파일에는 ansible 명령 작업이 수행되는 호스트 및 호스트 그룹을 정의합니다.

파일은 여러 형식을 지원하는데 오늘은 INI 형식의 파일에 대해서만 알아보겠습니다.

 

인벤토리 파일의 기본 위치는 '/etc/ansible/hosts'입니다. 기본 구성은 다음과 같습니다. 

mail.example.com

[webservers]
foo.example.com
bar.example.com

[dbservers]
one.example.com
two.example.com
three.example.com

 

"[]" 문자를 이용하여 용도별로 그룹을 지을 수 있습니다.

특정 서버는 여러 그룹에 속할 수 있으며,  모든 서버는 'all' 그룹에 속해있습니다.

 

 

서버 범위 추가하기


비슷한 패턴을 가진 서버가 많은 경우 각 서버의 이름을 별도로 나열하지 않고 범위로 추가할 수 있습니다.

[webservers]
www[01:50].example.com
[dbserver]
db[01:30].example.com

 

인벤토리에 변수 추가하기


인벤토리의 특정 서버 또는 서버 그룹과 관련된 변수 값을 저장할 수 있습니다.

단일 서버에 변수를 쉽게 할당 한 다음 나중에 playbook에서 사용할 수 있습니다.

[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909

 

아래와 같이 사용을 할수도 있습니다.

서버에 접속시 특정 계정을 지정하여 접속합니다.

[targets]

localhost              ansible_connection=local
other1.example.com     ansible_connection=ssh        ansible_user=myuser
other2.example.com     ansible_connection=ssh        ansible_user=myotheruser

 

여러 서버에 변수 추가 : 그룹


그룹의 모든 서버가 변수 값을 공유하면 해당 변수를 전체 그룹에 한 번에 적용할 수 있습니다.

[atlanta]
host1
host2

[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com

 

 

 

 

 

 

 

 

 

 

 

댓글

Designed by JB FACTORY

loading