第1章、ansible使用SSH的認證方式

image.png
第一種、創(chuàng)建秘鑰
ssh-keygen -f ~/.ssh/id_rsa sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id.rsa.pub -o'StrictHostKeyChecking=no'172.16.1.7ssh172.16.1.14"free -m"

image.png

image.png

image.png

image.png
第二種、使用ansible進行免密
vim etc/ansible/hosts[oldboy]172.16.1.12 ansible_ssh_user=root ansible_ssh_pass=123456172.16.1.14 ansible_ssh_user=root ansible_ssh_pass=123456vim /etc/ansible/ansible/ansible.cfg取消71行前面的#號ansible oldboy -mcommand-a"free -m"

image.png
第三章、ansible的模塊以及參數(shù)講解
查看使用幫助:? ? ansible-doc? -l? 查模塊的參數(shù):? ansible-doc -scommand
3.1、command模塊

image.png
3.2、shell模塊
功能說明:執(zhí)行一個命令在遠程節(jié)點上

image.png

image.png
實踐:增加文本文件

image.png
3.3、copy模塊
功能說明:復(fù)制文件到遠程主機

image.png
實踐1、把/etc?hosts拷貝到/opt下,權(quán)限設(shè)置400,用戶和用戶組為root

image.png
實踐2、把/etc/passwd拷貝到/tmp下改名為oldgirl,用戶和用戶組為oldboy,權(quán)限600,如果有同名文件覆蓋

image.png
3.4、scripts 模塊
功能:遠程節(jié)點上運行本地腳本模塊

image.png
3.5、file模塊
設(shè)置文件屬性

image.png
實踐,創(chuàng)建數(shù)據(jù)文件(普通文件 目錄 軟連接文件)
ansible oldgirl? -m file -a"dest=/tmp/oldboy state=directory"ansible oldgirl? -m file -a"dest=/tmp/123.txt state=touch"

image.png

image.png
3.6、yum模塊

image.png

image.png
3.7、systemd(Cent0s6 :service)
啟動停止服務(wù)

image.png

image.png

image.png
實踐1、停止crond

image.png
實踐2、啟動crond,設(shè)置開機啟動

image.png
實踐3、查看crond狀態(tài)

image.png
3.8、cron模塊
管理定時任務(wù)條目信息模塊

image.png

image.png
實踐1、注釋定時任務(wù),是定時任務(wù)失效

image.png
3.9、user模塊

3.10、mount模塊

image.png
3.11、group模塊
