본문 바로가기

리눅스

[Ansible] inventory(인벤토리) YAML 설정 - 2

728x90

inventory(인벤토리) YAML 설정 - 2

디렉터리 구조

level 1 level 2 level 3 level 4 비고
inventory        
  inventory.yaml      
--- --- --- ---  
  group_vars      
    hosts.yaml    
--- --- --- ---  
  blog      
    hosts.yaml    
    b-db    
      hosts.yaml  
    b-web    
      hosts.yaml  
--- --- --- ---  
  site-a      
    hosts.yaml    
    development    
      hosts.yaml  
    stage    
      hosts.yaml  
    production    
      hosts.yaml  

인벤토리 확인 

ansible-inventory -i ~/ansible-spec/inventory --graph
$ ansible-inventory -i ~/ansible-spec/inventory --graph
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
@all:
  |--@blog:
  |  |--@b-db:
  |  |  |--bdb-245
  |  |  |--bdb-246
  |  |--@b-web:
  |  |  |--admin-249
  |  |  |--admin-250
  |  |  |--api-247
  |  |  |--api-248
  |  |  |--web-245
  |  |  |--web-246
  |--@site-a:
  |  |--@development:
  |  |  |--devweb-214
  |  |--@production:
  |  |  |--websrv-231
  |  |  |--websrv-232
  |  |--@stage:
  |  |  |--stgweb-240
  |--@ungrouped:
  |  |--localhost

인벤토리 디렉터리 구조

tree
$ tree
.
├── blog
│   ├── b-db
│   │   └── hosts.yaml
│   ├── b-web
│   │   └── hosts.yaml
│   └── hosts.yaml
├── group_vars
│   └── all.yml
├── inventory.yaml
└── site-a
    ├── development
    │   └── hosts.yaml
    ├── hosts.yaml
    ├── production
    │   └── hosts.yaml
    └── stage
        └── hosts.yaml

group_vars 편집

$ cat ./group_vars/all.yml
ansible_connection: ssh
ansible_port: 22
ansible_ssh_user: ec2-user
ansible_ssh_private_key_file: ~/aws-key/keyfile.pem
##ansible_python_interpreter: /usr/bin/python

inventory.yaml 편집

$ cat ./inventory.yaml
all:
  children:
    blog:
    site-a:

  hosts:
    localhost:
      ansible_hostr: 192.168.50.24
      ip: 192.168.50.24

hosts.yaml 편집

$ cat ./site-a/hosts.yaml
site-a:
  children :
    development:
    stage:
    production:
$ cat ./site-a/development/hosts.yaml
development:
  hosts:
    devweb-214:
$ cat ./site-a/stage/hosts.yaml
stage:
  hosts:
    stgweb-240:
$ cat ./site-a/production/hosts.yaml
production:
  hosts:
    websrv-231:
    websrv-232:

 

참고URL

- [Ansible] 구성 설정(Configuration Settings) : https://scbyun.com/1373

- [Ansible] inventory(인벤토리) 설정 : https://scbyun.com/998

 

728x90