본문 바로가기

퍼블릭 클라우드

Ansible 인벤토리 설정

반응형

Ansible 인벤토리 설정

1. Ansible Inventory 기본 경로

Ansible은 기본적으로 다음 경로의 인벤토리 파일을 사용한다.

/etc/ansible/hosts

2. 인벤토리 설정

vim /etc/ansible/hosts
[aweb21]
asweb21 ansible_host=10.21.3.54
asweb22 ansible_host=10.21.4.199

[aweb21:vars]
ansible_user=ec2-user
ansible_port=22
ansible_ssh_private_key_file=~/aws-key/keyfile.pem

주요 옵션 설명

  • ansible_host: 실제 접속 대상 IP 또는 FQDN
  • ansible_user: 접속 사용자
  • ansible_port: SSH 포트 (기본 22)
  • ansible_ssh_private_key_file: SSH 개인키 경로

3. 인벤토리 확인

전체 호스트 목록 확인

ansible all --list-hosts
  hosts (2):
    asweb21
    asweb22
728x90

4. 연결 테스트 (ping 모듈)

모든 호스트 대상

ansible all -m ping
asweb21 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
asweb22 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

특정 그룹 대상

ansible aweb21 -m ping
asweb21 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
asweb22 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

특정 호스트 대상

ansible asweb21 -m ping
asweb21 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

5. 명령 실행 테스트 (uptime)

그룹 대상 실행

ansible aweb21 -a uptime
asweb22 | CHANGED | rc=0 >>
 07:42:18 up 42 min,  1 user,  load average: 0.00, 0.00, 0.00
asweb21 | CHANGED | rc=0 >>
 07:42:18 up 42 min,  1 user,  load average: 0.00, 0.00, 0.00

 

상세 로그 확인

ansible all -m ping -vvv

 

728x90
반응형