跳到主要内容

ansible模块-替换模块

ansible查看帮助方法

# 查看所有模块帮助信息
ansible-doc -l

# 指定查看某个模块参数用法
ansible-doc copy

1.lineinfile模块

ansible all -m lineinfile -a "path=/root/hehe regexp='^user admin' line='user hehe'"

lineinfile模块参数

参数说明
path文件路径
regexp匹配的规则,即要替换的内容
line替换为什么
stateabsent 删除

2.replace模块

ansible all -m replace -a "path=/root/hehe regexp='^user admin' replace='hehe'"

replace模块参数

参数说明
path文件路径
regexp匹配的规则,即要替换的内容
replace替换为什么