[Cloud] Ansible: ์ธ๋ฒคํ† ๋ฆฌ

MeltingOlafยท2022๋…„ 4์›” 15์ผ
0

[Cloud]

๋ชฉ๋ก ๋ณด๊ธฐ
2/25

โญ๏ธ ์ •์  ์ธ๋ฒคํ† ๋ฆฌ


  • ๊ธฐ๋ณธ ์ธ๋ฒคํ† ๋ฆฌ ํŒŒ์ผ: /etc/ansible/hosts
    --> ๊ฑฐ์˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ

  • ๊ธฐ๋ณธ ์œ„์น˜์— ์žˆ๋Š” ์ธ๋ฒคํ† ๋ฆฌ ํŒŒ์ผ ์•„๋‹ˆ๋ฉด: -i ์˜ต์…˜ ์‚ฌ์šฉ

  • ํฌ๋ฉง: ini, yaml

  • ini ํ˜•์‹์˜ ์˜ˆ

key=value

[Section]
key=value
key
mail.example.com

[webservers]
foo.example.com
bar.example.com
three.example.com

[dbservers]
one.example.com
two.example.com
three.example.com

[ ]: ์ธ๋ฒคํ† ๋ฆฌ ๊ทธ๋ฃน

  • ํ•˜๋‚˜์˜ ๋…ธ๋“œ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ๊ทธ๋ฃน์— ์†ํ•  ์ˆ˜ ์žˆ๋‹ค.
all:
  hosts:
    mail.example.com:
  children:
    webservers:
      hosts:
        foo.example.com:
        bar.example.com:
    dbservers:
      hosts:
        one.example.com:
        two.example.com:
        three.example.com:
        
  • ๊ธฐ๋ณธ ๊ทธ๋ฃน
    - all
    - ungrouped

๐Ÿ’ก ์ธ๋ฒคํ† ๋ฆฌ ์ƒ์„ฑ์€ ๊ฐ„๊ฒฐํ•˜๊ฒŒ

  • ๊ทธ๋ฃน์— ํ˜ธ์ŠคํŠธ๋ฅผ ๋ถ„๋ฅ˜
    - what
    - where
    - when

  • ํ˜ธ์ŠคํŠธ์˜ ๋ฒ”์œ„

[webservers]
www[01:50].example.com
192.168.100.[10:19]
  • ์ธ๋ฒคํ† ๋ฆฌ ๋ณ€์ˆ˜
[webservers]
www[01:50].example.com A=100 B=200
192.168.100.[10:19]
  • ์ธ๋ฒคํ† ๋ฆฌ ๊ทธ๋ฃน ๋ณ€์ˆ˜
[atlanta]
host1
host2

[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com
  • ์ค‘์ฒฉ ๊ทธ๋ฃน
[atlanta]
host1
host2

[raleigh]
host2
host3

[southeast:children]
atlanta
raleigh

[usa:children]
southeast

โญ๏ธ ์ธ๋ฒคํ† ๋ฆฌ ํŒŒ์ผ ํ™•์ธ


  • ์ƒ์„ฑํ•œ ์ธ๋ฒคํ† ๋ฆฌ ํŒŒ์ผ ๊ณ„์ธต ๊ตฌ์กฐ ํ™•์ธ
ansible-inventory -i <INVENTORY_FILE> --graph
  • JSON ํ˜•์‹ ๋ฐ ํ˜ธ์ŠคํŠธ/๊ทธ๋ฃน ๋ณ€์ˆ˜
ansible-inventory -i <INVENTORY_FILE> --list
  • ํ˜ธ์ŠคํŠธ์— ์„ค์ •๋œ ๋ณ€์ˆ˜ ํ™•์ธ
ansible-inventory -i <INVENTORY_FILE> --host <HOST>
  • ํ˜ธ์ŠคํŠธ ๋งค์นญ ํ™•์ธ
ansible <HOST_PATTERN> -i <INVENTORY_FILE> --list-hosts

โญ๏ธ ๊ตฌ์„ฑ ํŒŒ์ผ


  • ์„ค์ •ํŒŒ์ผ ์œ„์น˜
  1. ANSIBLE_CONFIG (environment variable if set)
touch /tmp/ans.cfg
export ANSIBLE_CONFIG=/tmp/ans.cfg
ansible --version

unset ANSIBLE_CONFIG
ansible --version
  1. ansible.cfg (ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ)
  2. ~/.ansible.cfg (ํ™ˆ๋””๋ ‰ํ† ๋ฆฌ)
  3. /etc/ansible/ansible.cfg : ๊ธฐ๋ณธ ์„ค์ • ํŒŒ์ผ
profile
How R U Today :)

0๊ฐœ์˜ ๋Œ“๊ธ€