zoukankan      html  css  js  c++  java
  • Ansible自动化运维工具(2)

    (5) ping模块
    检测客户端机器的连通性
    ansible webserver -m ping
    
    (6) group模块
    创建用户的附加组。
    ansible webserver -m group -a 'gid=2016 name=test'
    验证
    ansible webserver -m shell -a 'cat /etc/group | grep test'
    注意:
    command模块不支持管道符,而shell模块支持。
    
    (7) user模块
    该模块用于创建用户。
    ansible webserver -m user -a "name=test group=test"
    ansible webserver -m user -a "name=test state=absent remove=yes"
    
    (8) shell模块
    为ansible的默认模块。可运行所有客户端权限范围内的shell命令。可运行shell script支持管道符。
    ansible webserver -m shell -a "/tmp/echo_hello.sh"
    
    (9) script模块
    在远端客户机上执行本地Ansible机器中的shell脚本。相当于scp+shell的组合命令。
    ansible webserver -m script -a "~/hello.sh"
    
    (10) get_url模块
    在远程主机上通过url指示的位置下载,下载的文件抵达远程主机上。
    ansible webserver -m get_url -a 'url=http://ftp.linux.com/balabala.rpm dest=/tmp'
    
    (11) yum模块
    ~ config_file: yum的配置文件
    ~ disable_gpg_check: 关闭gpg check
    ~ diablerepo: 不启用某个源
    ~ enablerepo: 启用某个源
    ~ name: 要操作的软件包的名字,可以传递一个url或一个本地rpm包的路径
    ~ state: present(安装)|absent(删除)|latest(安装) 三种状态
    
    ansible 192.168.43.12 -m yum -a 'name=nginx enablerepo=nginx state=present'
    ansible 192.168.43.12 -m shell -a 'yum list installed | grep nginx'
    获取帮助
    ansible-doc yum
    
    (12) cron模块
    每天凌晨1点过1分执行对时。
    ansible webserver -m cron -a '"name=ntpdate time every day" minute="1" hour="1" job="/sbin/ntpdate ntp.api.bz >> /dev/null"'
    获取帮助
    ansible-doc cron
    
    (13) service模块
    客户端的服务管理。
    ansible webserver -m service -a "name=nginx state=started"
    ansible webserver -m service -a 'name=mysqld state=started enabled=yes'
    

    6. playbook

    导演,指挥,编排器。
    模版使用injia2模块处理。使用YAML描述定义。
    YAML的变量:{{varname}}
    配置文件的语法检查
    ansible-playbook ~/httpd.yml --list-hosts --list-tasks
    执行yaml配置
    ansible-book ~/httpd.yml -f 10
    10为并行进程数

  • 相关阅读:
    MyBatis 内连接association 左外连接collection
    mybatis的基本配置:实体类、配置文件、映射文件、工具类 、mapper接口
    SpringMVC 使用Form标签库制作登录表单
    SpringMVC 配置过滤器解决中文乱码问题
    用户登录模块————账户安全问题
    HashSet,TreeSet和LinkedHashSet的区别
    SpringMVC 服务器端验证
    php输出(下载)文件
    26进制(字母)转十进制算法
    PHP之可变变量
  • 原文地址:https://www.cnblogs.com/cerana/p/11129640.html
Copyright © 2011-2022 走看看