ansible常用模块及playbook基础
ansible的常用模块:
获取模块列表:
ansible-doc -l
command模块(省略):在远程主机运行命令;
shell模块:在远程主机在shell进程下运行命令,支持shell特性,如管道等;
copy模块:copies files to remote locations
用法:
(1) src = dest =
(2) content = dest =
owner,group,mode
cron模块:Manage cron.d and crontab entries.
minute=
day=
month=
weekday=
hour=
job=
*name=
state=
present:创建
absent:删除
例如 ansible all -m cron -a "minute=*/5 job=' /sbin/ntpdate 172.18.0.1 &> /dev/null ' name=Synctime"
fetch模块:从远程主机拉取文件
file模块:Sets attributes of files
用法:
(1)创建链接文件:*path= src= state=link
(2)修改属性:path= owner= mode= group=
(3)创建目录:path= state=directory
hostname模块:manage hostname
yum模块:
name=:程序包名称,可以带版本号;
state=
present,latest
absent
service模块:管理服务
*name=
state=
started
stopped
restarted
enabled=
runlevel=
user模块:管理用户账号
*name=
system=
uid=
shell=
group=
groups=
comment=
home=
setup模块:获取facts
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
YAML:
Playbooks的主要作用:让我们能够把多个相关联的任务 通过读取YAML格式的配置文件 一次跑出来
Playbooks的核心元素:
Tasks :任务
Variables 变量
Templates :包含了模板语法的文本文件;
Handlers :由特定条件触发的任务;
Roles