ansible模块记录

289 阅读1分钟

在学习ansible所使用的模块做一下记录,方便以后查看

模块查看命令

ansible-doc -l

//指定模块
ansible-doc -s ping

模块

fetch: Fetch files from remote nodes
ansible all -m fetch -a "src=远程 dest=本地"

copy: Copy files to remote locations
ansible all -m fetch -a "src=本地 dest=远程 mode="

file: Manage files and file properties
ansible all -m file -a "path=文件 owner= mode state="

blockinfile: Insert/update/remove a text block surrounded by marker lines
ansible all -m blockfile -a 'path= block= "" marker="#{mark}" insert[before|after]= backup=yes'

lineinfile: Manage lines in text files
ansible all -m lineinfile -a "path= line=''"

find: Return a list of files based on specific criteria
ansible all -m find -a "path= contains=内容 patternes=名称 size= age= hidden=yes"

replace: Replace all instances of a particular string in a file using a back-referenced regular expression
ansible all -m replace -a "path= regexp=匹配 replace=替换 backup=yes"

命令类模块

command模块
//creates参数存在是不会执行,removees参数不存在时不会执行
ansible all -m command -a "removes= ls"

shell模块
ansible all -m shell -a "executable=/bin/bash chdir= removes= ls;./hello.sh"

script模块
script: Runs a local script on a remote node after transferring it
ansible all -m script -a "hello.sh"

系统操作模块

cron模块
state=absent //删除任务
special_time=reboot yearly monthly weekly daily hourly
ansible all -m cron -a "name= minute=*/1 job='' backup=yes"

service模块
ansible all -m service -a "name=nginx state=[started|stoped|restarted|reload] enable=yes"

包管理模块

yum_repository:Add or remove YUM repositories
ansible all -m yum_repository -a "name=aliEpel description='ali EPEL' baeurl=https://mirrors.aliyun.com/epel/$releasever\Server/$basearch/"

yum: Manages packages with the `yum' package manager
//install (`present' or `installed', `latest'), or remove (`absent' or `removed')
ansible all -m yum -a "name=nginx state=installed disable_gpg_check=yes enablerepo=local"