ansible常用模块

lineinfile
匹配开头
ansible ansible-demo3 -m lineinfile -a 'path=/testdir/test regexp="^line" line="test lineinfile" backrefs=yes'
匹配结尾
ansible -i /root/hosts.txt all -m lineinfile -a 'path=/etc/default/grub regexp="saved$" line="GRUB_DEFAULT=0" backrefs=yes'
删除行
ansible ansible-demo3 -m lineinfile -a 'path=/testdir/test line="test lineinfile" state=absent'
插入行
ansible ansible-demo3 -m lineinfile -a 'path=/testdir/test line="test lineinfile"'


file模块
ansible webserver -m file -a "dest=/tmp/hosts mode=600"
copy模块
ansible webserver -m copy -a "src=/etc/hosts dest=/tmp/hosts"
yum模块
ansible webserver -m yum -a "name=vim state=present"
present:安装 等同于installed
absent:卸载 等同于removed
user模块
ansible webserver -m user -a "name=xiaoming password=securitytext"
securitytext是shadow中的加密密码
ansible webserver -m user -a "name=xiaoming state=absent remove=yes" 删除用户并移除家目录
service模块
ansible webserver -m service -a "name=httpd state=started" 确保服务打开
ansible webserver -m service -a "name=httpd state=restarted" 重启服务
脚本模块
ansible webserver -m script -a "/tmp/myapp/cpu_load.sh" ansible本地脚本传输到远程主机,并运行脚本

playbook
格式
---开头
...结尾

posted @ 2020-05-14 15:52  litton888  阅读(90)  评论(0)    收藏  举报