Ansible Inventory

CodingDaddy·2022년 3월 19일
0

Ansible -Study

목록 보기
1/11
post-thumbnail

인벤토리 설정 파일은 기본적으로 /etc/ansible/hosts에 정의 되어있다

  • ansible_host : 연결할 호스트의 이름. 당신이 원하는 호스트 별칭과 다를 경우 사용하여 임의 지정 가능
  • ansible_port : SSH 포트 번호. 기본값인 22가 아닐 경우 사용
  • ansible_user : SSH 접속에 사용할 유저 이름
  • ansible_ssh_pass : SSH 연결시 사용할 비밀번호. 이것은 보안에 취약하므로 –ask-pass 또는 SSH Keys 방식을 사용할 것은 권장
  • ansible_ssh_private_key_file : SSH 연결시에 사용할 SSH 비밀키 파일
  • ansible_ssh_common_args : sftp, scp, ssh와 같은 기본 명력을 사용할 때 항상 추가할 설정을 지정가능
[linux] 

ansible_connection=ssh

ansible_ssh_pass=password

[windows] 

ansible_connection=winrm

ansible_password=password

inventory 예제

mail.example.com	//이렇게 하면 Ad-hoc이나 Playbook에서 해당 호스트 네임으로 명령어 실행가능

# Web Servers
web1 ansible_host=server1.company.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Password123!
web2 ansible_host=server2.company.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Password123!
web3 ansible_host=server3.company.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Password123!

# Database Servers
db1 ansible_host=server4.company.com ansible_connection=winrm ansible_user=administrator ansible_password=Password123!

[web_servers]
web1
web2
web3

[db_servers]
db1

[all_servers:children]
web_servers
db_servers

비슷한 패턴을 가진 다수의 호스트를 지정하는 법

[webservers]
www[01:50].example.com  // for문 처리를 통해 01 ~ 50 번까지의 이름을 묶을 수 있다.

[databases]
db-[a:f].example.com

작성한 inventory를 playbook을 통해 실행하려면 andible.cfg 라는 파일에 등록해야 한다.

profile
Creative - DevOps in Korea

0개의 댓글