Print
카테고리: [ Cloud Computing & MSA ]
조회수: 3157

 

특히 각종 설치 작업 중에 수행해야만 하는 대화형 작업들이 있습니다. 이를 CHEF에서 자동화하기 위한 방법을 고민하였고, OS의 expect 명령어를 이용하여 구현하였습니다.

CHEF 자체 기능을 이용하고 싶었는데 아직 찾지 못했네요.

아래 예는 JBoss의 add-user.sh이라는 대화형 스크립트 수행을 CHEF로 자동화한 것입니다.

 

< 화면 >

# ./add-user.sh
 
What type of user do you wish to add?
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)
(a): a
 
Enter the details of the new user to add.
Realm (ManagementRealm) : [엔터]
Username : jbossadm
Password : admin
Re-enter Password : admin
About to add user 'jbossadm' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'jbossadm' to file '/jboss/6.1.0/standalone/configuration/mgmt-users.properties'
Added user 'jbossadm' to file '/jboss/6.1.0/domain/configuration/mgmt-users.properties'
Is this new user going to be used for one AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes

 

< recipe >

  bash "add-user.sh" do
    user "#{node[:JBOSS][:USER][:NAME]}"
    cwd "#{inst_home}"
    code << -EOH
    /usr/bin/expect -c 'spawn ./add-user.sh
    expect "(a): "
    send "a\n"
    expect "Realm (ManagementRealm) : "
    send "\n"
    expect "Username : "
    send "jbossadm\n"
    expect "Password : "
    send "admin\n"
    expect "Re-enter Password : "
    send "admin\n"
    expect "Is this correct yes/no? "
    send "yes\n"
    expect "yes/no? "
    send "yes\n"
    expect eof'
    EOH
  end

 

사실 CHEF 주제로 이야기를 했지만, 그냥 OS에서도 이용 가능하지요.