ansible自動化批量部署工具

yum install epel-release -y

yum install ansible -y

vim /etc/ansible/ansible.cfg

vim /etc/ansible/hosts

#在最後添加

[testhosts]

192.168.30.149

192.168.30.151

執行命令測試:

ansible testhosts -m command -a 'uptime'

 

 

ansible常用命令

ansible-doc -l  #查看支持的模塊
ansible-doc -s MODEL_NAME #查看模塊用法
ansible命令應用基礎
ansible <host-pattern> [options]
-f fork:啓動併發 線程數
-m model_name:要使用的模塊
-a args:特有的參數

ansible all -m ping  #查看client端是否正常ping通
ansible webserver -m setup  #查看客戶端信息
ansible webserver -m copy -a 'src=/root/git_test/code.txt  dest=/root/test'  #copy文件到client端
ansible webserver -m user -a "name=test state=present" #創建test用戶
ansible webserver -m user -a "name=test state=absent"  #刪除test用戶
ansible webserver -m yum -a 'name=epel-relese state=latest'   #yum安裝
ansible webserver -m systemd -a 'name=httpd state=stopped enabled=no'    #停止httpd服務
ansible webserver -m script -a '/tmp/test,sh'    #運行腳本
ansible webserver -m command 'date'    #查看時間

 

  • 批量執行命令

ansible asb -m shell -a "

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章