• (3)常用模块


    1)查看模块帮助:ansible-doc 模块名 例如:ansible-doc shell 搜索:/EX 查看案例

    2)ping模块:测试连接到目标主机的ssh端口是否能正常通信

    ansible webservers -m ping -o
    

    3)command模块:用于远程主机命令,默认模块,建议使用shell模块

    ansible webservers -m command -a 'uptime'
    

    4)shell模块:执行远程命令,一些简单的shell命令

        ansible webservers -m shell -a 'uptime'
    

    5)copy模块:复制文件到远程主机

    ansible webservers -m copy -a 'src=/etc/hosts dest=/tmp/hosts '
    ansible webservers -m copy -a 'src=/etc/hosts dest=/tmp/hosts backup=yes'
    

    6)user模块:创建和删除用户

    创建用户:ansible webservers -m user -a 'name=jack shell=/sbin/nologin'
    删除用户:ansible webservers -m user -a 'name=jack state=absent'
    	echo 123 | openssl passwd -1 -stdin
    	ansible webservers -m user -a 'name=jack password="$1$Ec9OCYTb$OJtUgRRglXNuEMmSCLfPl/"'
    

    7)yum模块:安装和卸载软件包

    安装:ansible webservers -m yum -a 'name=httpd state=latest'
    卸载:ansible webservers -m yum -a 'name=httpd state=absent'
    

    8)service模块:控制服务运行状态

    ansible webservers -m service -a 'name=httpd state=started enabled=yes'   \state是服务的启动,重启,关闭;enabled是服务器的开机启动
    ansible webservers -m service -a 'name=httpd  state=stopped enabled=no'	
    

    9)file模块:创建文件或目录

    创建文件:ansible webservers -m file -a 'path=/tmp/1.log mode=777 state=touch' 
    创建目录:ansible webservers -m file -a 'path=/tmp/dir1 mode=777 state=directory'
    

    10)cron模块:创建和移除定义任务

    ansible webservers -m cron -a 'name="test" minute="*/10" job="/bin/echo hello"'
    ansible webservers -m cron -a 'name="test2" minute="00" hour="03" job="/bin/echo hello"'
    移除:ansible webservers -m cron -a 'name="test2" minute="00" hour="03" job="/bin/echo hello" state=absent'
  • 相关阅读:
    沙县小吃炖罐做法 114沙县小吃配料网
    党参_百度百科
    EF架构~通过EF6的DbCommand拦截器来实现数据库读写分离~续~添加事务机制
    EF架构~通过EF6的DbCommand拦截器来实现数据库读写分离
    知方可补不足~Sqlserver中的几把锁和.net中的事务级别
    面对大数据,我们应该干的事~大话开篇
    EF架构~在T4模版中自定义属性的getter和setter
    SurfaceView的一个小应用:开发示波器
    Jetty入门
    ios ARC
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9004307.html
Copyright © 2020-2023  润新知