본문 바로가기

퍼블릭 클라우드

Ansible 인벤토리 설정 및 테스트

반응형

Ansible 인벤토리 설정 및 테스트

1. Ansible Inventory 기본 경로

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

/etc/ansible/hosts

2. 인벤토리 설정

vim /etc/ansible/hosts
[aweb21]
asweb21 ansible_host=10.21.3.54 ansible_connection=ssh ansible_por=22 ansible_user=ec2-user ansible_ssh_private_key_file=~/aws-key/keyfile.pem
asweb22 ansible_host=10.21.4.199 ansible_connection=ssh ansible_por=22 ansible_user=ec2-user ansible_ssh_private_key_file=~/aws-key/keyfile.pem

주요 옵션 설명

  • ansible_host: 실제 접속 대상 IP 또는 FQDN
  • ansible_connection: 접속 방식 (ssh)
  • ansible_port: SSH 포트 (기본 22)
  • ansible_user: 접속 사용자
  • 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"
}

 

그룹 변수 설정

[aweb21:vars]
ansible_user=ec2-user
ansible_port=22

접속 디버깅

ansible all -m ping -vvv

 

728x90
반응형