Software Workshop

salt 설치

  1. yum 또는 agt-get을 이용하여 설치
  2. salt-master, salt-minion, salt-syndic, salt-cloud, salt-ssh, salt-api
  3. ZeroMQ, pyzmq, PyCrypto, M2Crypto, msgpack-python, pyyaml, jinja2, MarkupSafe, apache-libcloud, Requests

salt 설정

Masterless 설정

http://docs.saltstack.com/en/latest/topics/tutorials/quickstart.html

curl -L <https://bootstrap.saltstack.com> -o install_salt.sh
sudo sh install_salt.sh

Remote execution

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

  1. /etc/salt/master 파일에 rest_cherrypy 설정 항목 추가
  2. salt-call —local tls.create_self_signed_cert 실행해서 인증서와 key 파일 생성
  3. sudo salt-master
  4. sudo salt-api
  5. curl -sSk <https://localhost:8000/login> -H ‘Accept: application/x-yaml’ -d username=saltdev -d password=saltdev -d eauth=auto 로 API 토큰 발급
  6. 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 호스트이름>