티스토리 뷰

DevOps/System&Tools

dynamic inventory

Jacob_baek 2018. 7. 24. 18:21

Ansible Dynamic Inventory

Ansible은 외부 inventory system을 쉽게 사용할 수 있도록 돕는다.

- https://docs.ansible.com/ansible/2.5/user_guide/intro_dynamic_inventory.html


아래 링크로 이동해보면 inventory관련 script example들이 존재한다.

- https://github.com/ansible/ansible/tree/devel/contrib/inventory


dynamic inventory의 사용이유

autoscaling 이나 외부 application들에 의해 관리되어지는 등 다양한 이유로 inventory file들은 유지되지 않기에 이를 dynamic하게 할당하기 위함이다.

간단하 예로 내부 시스템들중 Hostname에 mgmt가 붙는 시스템, Web Server 역할(80,443 port listen)을 수행하는 시스템 등을 사전에 정의한 script을 통해 선별하고 이를 자동으로 ansible host로 사용하게 된다.


dynamic inventory 사용법

  1. inventory_directory를 mkdir로 생성한다.
  2. ansible.cfg를 playbook이 존재하는 directory내에 생성한다.

    [defaults]

    inventory=inventory_directory


  3. inventory_directory내에 hosts 파일(그외의 이름도 가능) 혹은 example_script.py(당시 x permission추가되어 있어야 한다.) 를 복사한다.
  4. ansible all --list-hosts 실행
  5. hosts에 존재하는 list, example_script.py --list의 결과 list가 모두 출력된다.

해당 directory내 존재하는 script file(inventory_ignore_extensions 설정되지 않은 확장자) 및 host가 정의된 file들을 모두 읽어들인다.


custom dynamic inventory


다음조건을 만족하는 상황에서 dynamic inventory를 생성하여 사용 가능하다.


- 모든 결과는 JSON format으로 return되어야 한다.

- 다음 두가지 option을 인지하고 그에 맞는 JSON 결과가 출력되어야 한다.

  (--list, --host [HOST])


실제로 확인해보면 다음과 같은 return 을 수행하게 된다.


[jacob@jacob-laptop test_by_ansible]$ inven/inventory.py --list | python -m json.tool
{
    "python_hosts": {
        "hosts": [
            "192.168.1.1",
            "192.168.1.2"
        ],
        "vars": {
            "ansible_ssh_user": "testuser"
        }
    }
}


위 조건을 만족하는 경우라면 어떤 language든 상관없이 사용가능하다.

- https://docs.ansible.com/ansible/2.5/dev_guide/developing_inventory.html


대표적인 사용처


cloud provider나 LDAP, Cobbler, CMDB 와 같은 software로 부터 inventory를 가져올수 있다.

즉, 외부 inventory 저장소를 통해 손쉽게 이러한 모든 옵션을 가져올수 있다.

대표적인 대상은 Amazon EC2/Eucalyptus, Rackspace Cloud, OpenStack 등이 있다.


'DevOps > System&Tools' 카테고리의 다른 글

nexus  (0) 2019.11.12
k3s integrated with GitLab  (0) 2019.10.03
ansible cisco  (0) 2017.09.28
ansible with openstack  (0) 2017.07.28
ansible with vmware  (0) 2017.07.28
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함