Ansible模塊默認(rèn)存儲路徑: /usr/share/ansible
ansible 操作目標(biāo) -m 模塊名 -a 模塊參數(shù)
例子:
[root@www ansible]# ansible webservers -m command -a "w"
192.168.1.145 | success | rc=0 >>
14:07:16 up 1:33, 3 users, load average: 0.04, 0.02, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
centos tty7 :0 12:38 1:32m 5.63s 0.48s pam: gdm-passwo
centos pts/0 :0.0 12:38 1:23m 0.02s 0.02s /bin/bash
root pts/1 192.168.1.106 12:44 1:19m 0.09s 0.09s -bash
192.168.1.144 | success | rc=0 >>
17:38:23 up 3:26, 3 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
centos tty7 :0 15:44 3:26m 8.98s 0.47s pam: gdm-passwo
centos pts/0 :0.0 15:49 1:45m 0.04s 0.04s /bin/bash
root pts/1 192.168.1.106 15:53 1:45m 0.04s 0.04s -bash
[root@www ansible]#
運(yùn)程命令模塊:
模塊包括command(默認(rèn))主巍、script、shell妆丘。
command :在遠(yuǎn)程執(zhí)行權(quán)限內(nèi)的shell命令
script:在遠(yuǎn)程主機(jī)執(zhí)行控制端的腳本文件忆矛。
shell:在控制端執(zhí)行遠(yuǎn)程主機(jī)上的shell腳本文件
copy模塊:
控制端向目標(biāo)主機(jī)拷貝文件趣苏,類似scp
ansible webservers -m copy -a "src=/root/ dest=/tmp/"
stat模塊:
獲取遠(yuǎn)程主機(jī)文件狀態(tài)信息。
ansible webservers -m stat -a "path=/root/filename"
get_url模塊:
實(shí)現(xiàn)在遠(yuǎn)程主機(jī)下載指定url到遠(yuǎn)程主機(jī)上
ansible webservers -m get_url -a "url=http://www.baidu.com dest=/root/index.html"
yum 模塊:
實(shí)現(xiàn)包管理 有yum 和apt-get兩種
ansible webservers -m apt -a "pkg=curl state=latest"
ansible webservers -m yum -a "name=curl state=latest"
cron模塊:
遠(yuǎn)程主機(jī)crontab操作
ansible webservers -m cron -a "name='check file' hour='5,2' job='ls -al' "
mout模塊:
遠(yuǎn)程主機(jī)分掛載:
ansible wenservers -m mount -a "name=/mnt/data src=/dev/sda fstype =ext3"
service 模塊:
遠(yuǎn)程主機(jī)系統(tǒng)服務(wù)管理:
ansible webservers -m service -a "name=httpd state=restarted"
ansible webservers -m service -a "name=httpd state=started"
sysctl 包管理模塊:
遠(yuǎn)程主機(jī)sysctl配置
user 模塊:
遠(yuǎn)程主機(jī)系統(tǒng)用戶管理
添加用戶fuchao
ansible webservers -m user -a "name=fuchao "
刪除用戶:
ansible webservers -m user -a "name=fuchao state=absent remove=yes"