salt 설치
- yum 또는 agt-get을 이용하여 설치
- salt-master, salt-minion, salt-syndic, salt-cloud, salt-ssh, salt-api
- ZeroMQ, pyzmq, PyCrypto, M2Crypto, msgpack-python, pyyaml, jinja2, MarkupSafe, apache-libcloud, Requests
salt 설정
Masterless 설정
http://docs.saltstack.com/en/latest/topics/tutorials/quickstart.html
- master없이 로컬 파일만 가지고 configuration management
curl -L <https://bootstrap.saltstack.com> -o install_salt.sh
sudo sh install_salt.sh
- /etc/salt/master 파일에 file_client: local 설정
- top.sls 파일, webserver.sls 파일 등의 state 파일들을 작성함
sudo salt-call —local state.highstate로 실행
Remote execution
salt ‘*’ test.pingsalt -G ‘os:CentOS’ test.ping# grain 조건에 따라salt -E ’10.77.\\w+’ test.ping# RE matchingsalt ‘*’ grains.itemssalt ‘*’ grains get idsalt ‘*’ cmd.run ‘ls -l’salt ‘*’ disk.usagesalt ‘*’ pkg.install vimsalt ‘*’ network.interfacessalt ‘*’ cmd.exec_code python ‘import sys; print sys.version’]salt ‘*’ pip.install salt timeout=5 upgrade=True- salt-call은 master를 통하지 않고 minion에 직접 접속해서 실행해보는 커맨드임
State
master의 /srv/salt 디렉토리에 emacs.sls 파일을 생성하고
salt ‘*’ sate.sls emacs
emacs.sls
emacs:
pkg.installed
/root/.emacs:
file.managed:
- source: <salt://emacs> (/srv/salt 디렉토리)
- mode: 644
- user: root
- group: root
salt ‘*’ state.sls emacs (설정파일까지 설치해줌)
apache.sls
apache:
pkg.installed: \[\]
service.running:
- require:
- pkg: apache
yaml_jinja를 통해 php처럼 SSI 로직을 담을 수 있음
apache:
pkg.installed:
{% if grains['os'] == 'RedHat'%}
- name: httpd
{% endif %}
service.running:
{% if grains['os'] == 'RedHat'%}
- name: httpd
{% endif %}
- watch:
- pkg: apache
- file: /etc/httpd/conf/httpd.conf
- user: apache
user.present:
- uid: 87
- gid: 87
- home: /var/www/html
- shell: /bin/nologin
- require:
- group: apache
group.present:
- gid: 87
- require:
- pkg: apache
/etc/httpd/conf/httpd.conf:
file.managed:
- source: salt://apache/httpd.conf
- user: root
- group: root
- mode: 644
salt API
pip install cherrypy
http://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html
cherrypy
- netapi가 Salt의 API 전반을 담당
- rest_cherrypy는 REST API 담당
- rest_tornado는 non-blocking REST API 담당
- rest_wsgi는 minimal REST API 담당
- rest_cherrypy 채택
- /etc/salt/master 파일에 rest_cherrypy 설정 항목 추가
salt-call —local tls.create_self_signed_cert실행해서 인증서와 key 파일 생성sudo salt-mastersudo salt-apicurl -sSk <https://localhost:8000/login> -H ‘Accept: application/x-yaml’ -d username=saltdev -d password=saltdev -d eauth=auto로 API 토큰 발급- curl -sSk https://localhost:8000 -H 'Accept: application/x-yaml' -H 'X-Auth-Token: 토큰문자열' -d client=local -d tgt='*' -d fun=test.ping
쿠키 이용도 가능함
write
curl -sSk <https://localhost:8000/login> -c ~/cookies.txt -H 'Accept: application/x-yaml' -d username=saltdev -d password=saltdev -d eauth=auto
read
curl -sSk <https://localhost:8000> -b ~/cookies.txt -H 'Accept: application/x-yaml' -d client=local -d tgt='*' -d fun=test.ping
Troubleshooting
[ERROR ] Not loading 'salt.loaded.int.netapi.rest_cherrypy'. Error loading CherryPy: No module named cherrypy 오류
salt-api에 환경변수 PYTHONPATH가 하드코드되어 있음
[Error ] The salt Master has cached the public key for this node, this salt minion will wait for 10 seconds before attempting to re-authenticate 오류
key가 cache되어 있으므로 salt-key -D를 실행하여 키를 삭제해주면 됨
salt-key -a <IP주소 or 호스트이름>