1.fetch模塊, 將遠程機器上的文件拉取到本地,以ip或者主機名生成目錄,並保留原來的目錄結構,與copy模塊的功能相反.python
主要參數 : dest -- 目標地址linux
src -- 源地址web
例子 : ansible web -m fetch -a "dest=/tmp src=/var/log/cron" #表示把遠程主機上/var/log/cron下的文件copy到本機的/tmp下.redis
2.yum模塊shell
首先,linux自帶的yum有其自身的功能 : django
linux中yum源的配置格式 :centos
[epel] # 名稱
name=Extra Packages for Enterprise Linux 7 - $basearch # 描述信息
baseurl=http://mirrors.aliyun.com/epel/7/$basearch # yum源的地址
failovermethod=priority
enabled=1 # 指定yum源是否可用,1表明可用,0表明不可用
gpgcheck=0 # 是否檢查gpgkey文件,0表明不檢查,1表明的檢查
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
yum grouplist #查看包組
yum groupinstall # 安裝包組fetch
查看包安裝狀態 : ui
yum list|grep redis @表明安裝成功
rpm -qa 查看全部的包
rpm -ql 查看包安裝生成的文件url
而後看一下ansible中的yum模塊所帶的參數 :
disable_gpg_check # 是否要檢查key
disablerepo # 禁用repo
enablerepo #啓用repo
name # 包名
state # 狀態 installed removed
示例 :
ansible web -m yum -a "name=python2-pip" # 安裝一個包
ansible web -m yum -a "name='@Development Tools'" # 安裝包組
ansible web -m yum -a "name=redis,python2-pip" # 同時安裝多個包
ansible web -m yum -a "name=redis state=absent" # 卸載
3.pip模塊
linux中自帶python2版本,其pip也有自帶的功能 :
pip list #查看全部的python第三方包
pip freeze > a.txt # 導出
pip install -r a.txt # 安裝
ansible中的pip模塊參數 :
requirements #導出的文件
name # 包名
virtualenv # 虛擬環境
ansible web -m pip -a "name=django==1.11.18" # 安裝
4.service模塊
linux中自帶的一些服務 :
ps -ef|grep redis # 查看進程
ss -tnlp #查看端口信息
# 啓動服務
systemctl start redis centos7
service redis start centos6
# 開機自啓動
systemctl enable redis centos7
chkconfig redis on centos6
ansible中的service模塊 :
enabled # 設置開機自啓動 name # 名稱 state : started stopped restarted reloaded
示例 :
ansible web -m service -a "name=redis state=started" # 啓動
ansible web -m service -a "name=redis state=stopped" # 關閉
ansible web -m service -a "name=redis state=started enabled=yes" # 啓動並設置開機自啓動
5.cron模塊
linux中的定時任務 :
crontab -l # 查看計劃任務
crontab -r # 刪除全部的計劃任務
crontab -e # 編輯計劃任務
ansible中的cron模塊 :
day # 天
hour # 小時
job #任務
minute #分鐘
month # 月
name #名字,描述信息,不能夠重複
state # 狀態
user # 執行計劃任務的用戶
weekday # 周
disabled # 禁止
示例 :
ansible web -m cron -a "minute=21 job='touch /tmp/cron.txt' name=touchfile" # 設置計劃任務
ansible web -m cron -a "minute=23 job='touch /tmp/cron.txt' name=touchfile4 disabled=yes" # 禁用計劃任務,表現爲加註釋
ansible web -m cron -a "name=touchfile4 state=absent" # 刪除計劃任務
6.user模塊
linux中的useradd參數 :
-d # 指定家目錄
-g # 組id
-G, --groups GROUPS # 附加組
-r, --system # 建立系統用戶
-s, --shell SHELL # 登錄shell
-u, --uid UID #用戶id
示例 :
useradd -s /sbin/nologin -u 2000 -d /opt/wusir 用戶名 #建立用戶,指定用戶的登錄shell,id,家目錄
useradd -s /sbin/nologin -G root,wusir -d /opt/wusir2 用戶名 #指定附加組,最大的後面+1
useradd -r 用戶名 # 建立系統用戶,從999倒序
刪除用戶 :
userdel 用戶名 # 刪除用戶
userdel -r 用戶名 # 刪除用戶並刪除用戶的家目錄
ansible中的user模塊 :
group # 組
groups #附加組
home #家目錄
name #用戶名
password #密碼
shell #登錄shell
remove # 刪除用戶並刪除用戶的家目錄
state # 狀態
system #系統用戶
uid # 用戶id
示例:
ansible db -m user -a "name=用戶名 shell=/sbin/nologin home=/opt/f1 uid=2000 group=root" # 建立用戶,並指定用戶的家目錄,登錄shell,uid,組
ansible db -m user -a "name=用戶名 system=yes" #建立系統用戶
ansible db -m user -a "name=用戶名 state=absent" # 刪除用戶
ansible db -m user -a "name=用戶名 state=absent remove=yes" # 刪除用戶並刪除用戶的家目錄
7.group模塊
linux中一些關於組的操做 :
groupadd #建立組
groupdel #刪除組
-g 指定組的id
-r 指定系統組
ansible中的group模塊參數:
gid #組的id
name # 組名
state #狀態
system #系統組
示例 :
ansible db -m group -a "name=canglaoshi" #建立普通組
ansible db -m group -a "name=wutenglan system=yes" # 建立系統組
ansible db -m group -a "name=wutenglan state=absent" # 刪除組