Chef Server에서 Node Object에 정의한 run_list에는 실행할 recipe가 열거되어 있지만, 노드 수가 많아지면 관리가 힘들어진다. 예를 들어, 같은 recipe를 적용하는 5개의 노드가 있을 때 새로운 recipe를 추가한다는 가정을 한다. 이런 경우에는 recipe를 다섯 번이나 생성하는 것은 번거롭다. 이는 Role을 통해 run_list나 Attribute를 노드의 역할별로 그루핑을 수행하면 간단히 해결된다.
1. Role
Role 생성 예제를 위해 테스트 Role을 생성한다. 테스트 Role에서는 sample2, loging_users recipe를 수행한다.
- test role 생성
[root@ChefWorkstation] $ export EDITOR=vi
[root@ChefWorkstation] $ knife role create role_test
{
"name": "role_test",
"description": "",
"json_class": "Chef::Role",
"default_attributes": {
},
"override_attributes": {
},
"chef_type": "role",
"run_list": [
"recipe[sample2]”,
"recipe[login_users]"
],
"env_run_lists": {
}
}
:wq
Created role[role_test]
- Node Object의 run_list에 recipe 등록
[root@ChefWorkstation] $ knife node run_list set 172.16.1.148 role[role_test]
172.16.1.148 :
run_list : role[role_test]
- Chef Client에 적용
[root@ChefWorkstation] $ knife ssh ‘name:172.16.1.148’ ‘sudo chef-client’
172.16.1.148 Starting Chef Client, version 12.4.1
172.16.1.148 resolving cookbooks for run list: ["login_users", "sample2"]
172.16.1.148 Synchronizing Cookbooks:
172.16.1.148 - sample2
172.16.1.148 - login_users
…
172.16.1.148 Running handlers:
172.16.1.148 Running handlers complete
172.16.1.148 Chef Client finished, 0/6 resources updated in 2.942807 seconds
2. Role에 Attribute 정의
Role을 통해 그루핑 가능한 것은 run_list만이 아니라 Attribute도 Role별로 정의할 수 있다. Role을 사용하면 여러 노드의 상태 관리가 논리적이고 깔끔하게 이루어진다.
default_attributes "apache2" => {
"listen_ports" => [ "80", "443" ]
}
참 고 문 헌
[1] 이토 나오야, 박상욱, “인프라스트럭처 자동화 프레임워크 Chef Solo 입문”, 제이펍, 2014.
'Information Technology > Automation' 카테고리의 다른 글
[Chef] 기타 Resource 및 Recipe (0) | 2023.03.20 |
---|---|
[Chef] Opscode Community Cookbook (0) | 2023.03.20 |
[Chef] Data Bag (0) | 2023.03.20 |
[Chef] Attribute (0) | 2023.03.20 |
[Chef] Definition (0) | 2023.03.20 |