cobbler 批量安裝系統(tǒng)
ansible 簡(jiǎn)單配置之inventory(清單)
-
免秘鑰登錄系統(tǒng)
ssh-keygen ssh-copy-id -i id_rsa.pub xzdnsaipso@111.11.252.132 iptables -I INPUT -s 111.11.208.2 -p tcp --dport 22 -j ACCEPT
-
配置文件
vim /etc/ansible/hosts
ansible modules (模塊)
-
參考:
https://docs.ansible.com/ansible/latest/modules/modules_by_category.html
-
commad (命令)
/usr/local/bin/ansible DNS-cache -m command -a "df -h" /usr/local/bin/ansible DNS-cache -m command -a "free -g" /usr/local/bin/ansible all -m command -a "ifconfig eth0"
-
shell (管道)
/usr/local/bin/ansible DNS -m shell -a "ifconfig |grep eth*" /usr/local/bin/ansible DNS -m shell -a "ifconfig eth0 | awk 'NR==2'" /usr/local/bin/ansible DNS -m shell -a "ifconfig eth0 | awk 'NR==2';df -h;free -g;w"
-
yum 安裝軟件炼蛤,僅限r(nóng)oot用戶(hù)
/usr/local/bin/ansible other -m yum -a "name=httpd state=installed" /usr/local/bin/ansible other -m shell -a "rpm -qa|grep httpd" /usr/local/bin/ansible other -m yum -a "name=httpd state=removed"
-
copy (copy文件 向文件寫(xiě)東西)
ansible-doc copy #查看copy模塊用法 /usr/local/bin/ansible other -m copy -a "src=/etc/hosts dest=/tmp/test" /usr/local/bin/ansible other -m command -a "ls /tmp/test -l" /usr/local/bin/ansible other -m command -a "cat /tmp/test" /usr/local/bin/ansible other -m copy -a "src=/etc/hosts dest=/tmp/test.txt owner=alipms group=alipms mode=0600" /usr/local/bin/ansible other -m copy -a "src=/etc/hosts dest=/tmp/test backup=yes" /usr/local/bin/ansible other -m copy -a "content='ansible 123 com' dest=/tmp/test backup=yes"
-
service 啟動(dòng)服務(wù)
/usr/local/bin/ansible other -m service -a "name=httpd state=started|stopped|restarted|reloaded enabled=yes" enabled 是否讓服務(wù)器開(kāi)啟自動(dòng)啟動(dòng) /usr/local/bin/ansible other -m copy -a "content='This is ansible test.' dest=/var/www/html/index.html" /usr/local/bin/ansible other -m service -a "name=httpd state=restarted"
script (直接執(zhí)行shell腳本,但是少用)
/usr/local/bin/ansible other -m script -a "script.sh"
-
file 創(chuàng)建文件和目錄
/usr/local/bin/ansible other -m file -a "path=/tmp/file_test state=directory" /usr/local/bin/ansible other -m file -a "path=/tmp/file_test/test.txt state=touch" path recurse 遞歸 state directory 在遠(yuǎn)端創(chuàng)建目錄 touch 在遠(yuǎn)端創(chuàng)建文件 link 創(chuàng)建軟連接文件 hard 創(chuàng)建硬連接文件 mode 設(shè)置文件或目錄券商 owner group
group(root用戶(hù))
/usr/local/bin/ansible other -m group -a "name=gps gid=888"
-
user(root用戶(hù))
/usr/local/bin/ansible other -m user -a "name=test uid=999 group=888 shell=/sbin/nologin create_home=no" /usr/local/bin/ansible other -m user -a "name=test uid=999 group=888 shell=/sbin/nologin state=absen" 刪除用戶(hù) uid group groups 指定附加組 password 給用戶(hù)添加密碼 shell 指定用戶(hù)登錄的shell create_home 是否創(chuàng)建家目錄 ----------------------------------------------------------------------- echo 123.com | openssl passwd -salt 'ok.' -stdin ; echo 123.com | openssl passwd -salt 'no.' -stdin $1$123456$ubeM.omJvWFVdZGIzK6BV. /usr/local/bin/ansible other -m user -a "name=xlm password='$1$NWCVGKb/$uozMg09Bsz2FNGjW72HGA.'" 創(chuàng)建xlm用戶(hù)并設(shè)定密碼為:123.com
-
cron
ansible-doc cron 查看幫助 /usr/local/bin/ansible other -m cron -a "minute=* hour=* day=* month=* weekday=* job='/bin/sh test.sh'" /usr/local/bin/ansible other -m cron -a "job='/bin/sh test.sh'" /usr/local/bin/ansible other -m cron -a "name='ansible add crontd.' job='/bin/sh test.sh'" /usr/local/bin/ansible other -m cron -a "name='ansible add crontd.' job='/bin/sh test.sh' state=absent" /usr/local/bin/ansible other -m cron -a "name='ansible add crontd.' job='/bin/sh test.sh' disabled=yes" 注釋定時(shí)任務(wù)
-
mount (掛載目錄設(shè)備僅限r(nóng)oot用戶(hù))
/usr/local/bin/ansible other -m mount -a "path=/backup src=111.11.252.86:/data fstype=nfs opts=defaults state=present" 只寫(xiě)配置文件 /etc/fstab,并不會(huì)掛載 /usr/local/bin/ansible other -m mount -a "path=/backup src=111.11.252.86:/data fstype=nfs opts=defaults state=mounted" state absent 卸載設(shè)備并清理寫(xiě)入到/etc/fstab配置 mounted 掛載設(shè)備并將配置寫(xiě)入/etc/fstab配置 present 僅將掛載配置寫(xiě)入到/etc/fstab配置汇在,并不會(huì)掛載(雞肋,不用) unmounted 臨時(shí)卸載,不會(huì)清理/etc/fstab配置
- 檢查主機(jī)是否ping
/usr/local/bin/ansible all -m ping /usr/local/bin/ansible DNS-cache -m ping /usr/local/bin/ansible 111.11.252.86 -m ping