-
Ansible優(yōu)點
查看全部 -
代碼塊2.0
查看全部 -
代碼塊1.0
查看全部 -
Python運(yùn)維查看全部
-
baocun查看全部
-
自動化運(yùn)維工具
1、部署類:jenkins
2、環(huán)境類:ansible
3、監(jiān)控類:nagios
主要函數(shù)講解:
os.system
? 功能:執(zhí)行命令
? 返回:命令的返回值
? 補(bǔ)充:命令的輸出會輸出到標(biāo)準(zhǔn)輸出
raw_input()
? 功能:暫停程序運(yùn)行,等待用戶輸入
? 返回:用戶輸入的內(nèi)容
查看全部 -
ansible 默認(rèn)按這個位置找配置路徑:(具有優(yōu)先級)查看全部 -
Ansible的優(yōu)勢:無客戶端,推送式,第三方模塊特別多
查看全部 -
Ansible的功能:系統(tǒng)環(huán)境配置,安裝軟件,持續(xù)集成,熱回滾
查看全部 -
Ansible 自動化管理IT資源工具
查看全部 -
1、安裝salt-api、
[root@cenots7 salt]# yum -y install salt-api
2、添加調(diào)用api用戶、
[root@cenots7 salt]# useradd -M test && echo test | passwd test --stdin
3、生成加密證書、
[root@cenots7 salt]# salt-call --local tls.create_self_signed_cert
'tls' __virtual__ returned False: ['PyOpenSSL version 0.10 or later must be installed before this module can be used.']
報錯了、
4、根據(jù)報錯安裝PyOpenSSL、
4.1 將pip源指向阿里云、
[root@cenots7 salt]# cat /etc/pip.conf?
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
4.2、安裝PyOpenSSL
[root@cenots7 salt]# pip install PyOpenSSL
----省略輸出----
Successfully installed PyOpenSSL-19.0.0 asn1crypto-0.24.0 cffi-1.12.2 cryptography-2.6.1
5、修改配置文件、
[root@cenots7 salt]# tail -15 /etc/salt/master
#####? ? ? Returner settings? ? ? ? ? ######
############################################
# Which returner(s) will be used for minion's result:
#return: mysql
rest_cherrypy:
? ? port: 8000
? ? debug: True
? ? ssl_crt: /etc/pki/tls/certs/localhost.crt
? ? ssl_key: /etc/pki/tls/certs/localhost.key
external_auth:
? ? pam:
? ? ? ? test:
? ? ? ? ? ? - .*
? ? ? ? ? ? - '@whell'
? ? ? ? ? ? - '@runner'
6、重啟下salt-master和salt-api
[root@cenots7 salt]# systemctl restart salt-master salt-api
[root@cenots7 salt]# ps -ef | grep api
root? ? ? 38644? ? ? 1 22 23:52 ?? ? ? ? 00:00:00 /usr/bin/python /usr/bin/salt-api
root? ? ? 38653? 38644? 9 23:52 ?? ? ? ? 00:00:00 /usr/bin/python /usr/bin/salt-api
root? ? ? 38760? ?9267? 0 23:52 pts/1? ? 00:00:00 grep --color=auto api
[root@cenots7 salt]# netstat -anp | grep :8000
tcp? ? ? ? 0? ? ? 0 0.0.0.0:8000? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ?LISTEN? ? ? 38653/python? ? ? ??
tcp? ? ? ? 0? ? ? 0 127.0.0.1:39240? ? ? ? ?127.0.0.1:8000? ? ? ? ? TIME_WAIT? ?-? ? ? ? ? ? ? ? ? ?
tcp? ? ? ? 0? ? ? 0 127.0.0.1:39242? ? ? ? ?127.0.0.1:8000? ? ? ? ? TIME_WAIT? ?-? ? ? ? ? ? ? ? ? ?
tcp? ? ? ? 0? ? ? 0 127.0.0.1:39248? ? ? ? ?127.0.0.1:8000? ? ? ? ? TIME_WAIT? ?-?
7、編寫獲取api token的腳本、和使用api的腳本、
更多幫助信息查看:/usr/lib/python2.7/site-packages/salt/netapi/rest_cherrypy/app.py
[root@cenots7 salt]# cat login_api.sh?
curl -sSk https://localhost:8000/login \
-H 'Accept: application/x-yaml' \
-d username=test \
-d password=test \
-d eauth=pam
[root@cenots7 salt]# cat use_api.sh?
curl -sSk https://localhost:8000 \
? ? -H 'Accept: application/x-yaml' \
? ? -H "X-Auth-Token: $1"\
? ? -d client=local \
? ? -d tgt='*' \
? ? -d fun=test.ping
8、獲取api token、
[root@cenots7 salt]# sh login_api.sh?
return:
- eauth: pam
? expire: 1553488982.633511
? perms:
? - .*
? - '@whell'
? - '@runner'
? start: 1553445782.633511
? token: 059a295bef677e06ee173bc79c4f38450f65e06e
? user: test
9、通過獲取的token調(diào)用api、
[root@cenots7 salt]# sh use_api.sh 059a295bef677e06ee173bc79c4f38450f65e06e
return:
- minion103: true
? minion104: true
查看全部 -
1、自定義一個模塊重命名的文件、
[root@cenots7 salt]# cat /srv/salt/_modules/test.py?
__virtualname__ = 'hello'
def __virtual__():
? ? return __virtualname__
def test():
? ? return 'hello world, this is test custom modules'
2、修改自定義模塊后要記得同步、
[root@cenots7 salt]# salt '*103' saltutil.sync_modules
minion103:
? ? - modules.test
3、調(diào)用自定義模塊、
[root@cenots7 salt]# salt '*103' test.test
minion103:
? ? Module 'test' is not available.
ERROR: Minions returned with non-zero exit code
[root@cenots7 salt]# salt '*103' hello
minion103:
? ? Module 'hello' is not available.
ERROR: Minions returned with non-zero exit code
[root@cenots7 salt]# salt '*103' test.hello
minion103:
? ? Module 'test' is not available.
ERROR: Minions returned with non-zero exit code
[root@cenots7 salt]# salt '*103' hello.test
minion103:
? ? hello world, this is test custom modules
查看全部 -
1、修改/etc/salt/master中module_dirs、指向/srv/salt/_module、如下:
module_dirs:
? - /srv/salt/_modules
2、創(chuàng)建/srv/salt/_modules/
[root@cenots7 salt]# mkdir -p?/srv/salt/_modules/
3、編寫自定義模塊、
[root@cenots7 salt]# cat?/srv/salt/_modules/temp.py
#!/usr/bin/env python
# -*- encoding: utf8 -*-
def test():
? ? print "hello world"
? ? return "how do you do"
4、將模塊同步到minion、
[root@cenots7 salt]# salt '*' saltutil.sync_modules
minion103:
? ? - modules.temp
minion104:
? ? - modules.temp
5、調(diào)用自定義的模塊、
[root@cenots7 salt]# salt '*' temp.test
minion103:
? ? how do you do
minion104:
? ? how do you do
查看全部 -
salt 'minion103' sys.doc?cmd.run??>>>?查看cmd.run的幫助信息、
salt 'minion103'?sys.list_modules??>>>查看支持所有模塊、
查看全部 -
ansible 與saltstack執(zhí)行ping命令耗費(fèi)時間的對比、
[root@cenots7 ~]# time ansible test -m ping
10.16.168.104 | SUCCESS => {
? ? "changed": false,?
? ? "ping": "pong"
}
10.16.168.103 | SUCCESS => {
? ? "changed": false,?
? ? "ping": "pong"
}
real 0m4.777s
user 0m2.626s
sys 0m2.988s
[root@cenots7 ~]# time salt '*' test.ping
minion104:
? ? True
minion103:
? ? True
real 0m0.979s
user 0m0.577s
sys 0m0.138s
查看全部
舉報