Saltstack的httpapipython
1.在官網跟新yum源信息:json
2.yum安裝ubuntu
yum install -y gcc make python-devel libffi-devel salt-api opensslcentos
pip install cherrypyapi
生成證書:app
#cd /etc/saltcurl
#mkdir keycrtpost
#cd keycrturl
#openssl genrsa –out key.pem 4098centos7
#openssl req –new –x 509 –key key.pem –out cert.pem –days 1826
3. 配置用戶以及權限:
a.首先須要在master上檢查配置文件:
default_include: master.d/*.conf
interface: 192.168.48.128
conf_file: /etc/salt/master
pki_dir: /etc/salt/pki/master
auto_accept: True
file_roots:
base:
- /srv/salt/
log_file: /var/log/salt/master
log_level_logfile: debug
b. 配置salt-api的配置文件:
[root@localhost master.d]# cd /etc/salt/master.d/
[root@localhost master.d]# ls api.conf eauth.conf
[root@localhost master.d]#
[root@localhost master.d]# cat api.conf
rest_cherrypy:
port: 8000
ssl_crt: /etc/salt/keycrt/cert.pem
ssl_key: /etc/salt/keycrt/key.pem
[root@localhost master.d]# cat eauth.conf
external_auth:
pam:
saltapi:
- .*
- '@wheel'
- '@runner'
建立用戶:
c. 建立用戶
useradd -M -s /sbin/nologin/ saltapi
echo 「saltapi」 |passwd saltapi --stdin
注意這個應用名和上面的saltapi要對應一致。
啓動salt-api
systemctl restart salt-api
netstat –anp |grep 8000
對於ubuntu系統,咱們可能使用https也是無法使用,咱們能夠使用http協議,具體的配置以下:
root@ling-virtual-machine:/etc/salt/master.d# cat api.conf
rest_cherrypy:
port: 8000
disable_ssl: True
#ssl_crt: /etc/salt/keycrt/cert.pem
#ssl_key: /etc/salt/keycrt/key.pem
注意以上的: disable_ssl: True
而後把ssl祕鑰和公鑰註釋掉,eauth.conf不發生變化
獲取tocken: http協議的
curl -X POST -k http://192.168.48.134:8000/login -d username='saltapi' -d password='saltapi' -d eauth='pam' |python -mjson.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 240 100 197 100 43 45 9 0:00:04 0:00:04 --:--:-- 45
{
"return": [
{
"eauth": "pam",
"expire": 1517235285.554001,
"perms": [
".*",
"@wheel",
"@runner"
],
"start": 1517192085.554001,
"token": "105ee1f28109d67855ce7898e75e173a678f5174",
"user": "saltapi"
}
]
}
1 獲取tocken: https協議的(centos7)
2 [root@localhost master.d]# curl -X POST -k https://192.168.48.131:8000/login -d username='saltapi' -d password='saltapi' -d eauth='pam' |python -mjson.tool
3 % Total % Received % Xferd Average Speed Time Time Time Current 4 Dload Upload Total Spent Left Speed 5 100 240 100 197 100 43 908 198 --:--:-- --:--:-- --:--:-- 912 6 { 7 "return": [ 8 { 9 "eauth": "pam", 10 "expire": 1517235312.537542, 11 "perms": [ 12 ".*", 13 "@wheel", 14 "@runner" 15 ], 16 "start": 1517192112.537541, 17 "token": "bd5922438e9ae10db039816728c2b86f9462a0bb", 18 "user": "saltapi" 19 } 20 ] 21 }
Headers裏面是用來存放headers的信息的
Body裏面來存放數據的,經常使用的data數據就是x-www-
form-urlencoded form-data 是用來存放頁面form表單數據的
只要salt-api不重啓,tocken就不會過時,salt-api重啓之後,tocken就會過時
經過postman來獲取執行module:
經過curl來獲取執行module:
root@ling-virtual-machine:/etc/salt/master.d# curl -k http://192.168.48.134:8000 -H "Accept: application/x-yaml" -H "X-Auth-Token: ec623ed62de7dd62cfdadb94ad0044b7f46c9549" -d client='local' -d tgt='*' -d fun='test.ping'
return:
192.168.48.129: true
運行runner
root@ling-virtual-machine:/etc/salt/master.d# curl -k http://192.168.48.134:8000 -H "Accept: application/x-yaml" -H "X-Auth-Token: ec623ed62de7dd62cfdadb94ad0044b7f46c9549" -d client='runner' -d fun='manage.status'
return:
- down: []
up:
- 192.168.48.129
1.自定義一些module
2. 線上使用runner的實例