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为并行进程数

  • 相关阅读:
    委托和事件
    解决kalilinux:“下列签名无效: KEYEXPIRED 1425567400"
    【c# 学习笔记】委托的使用
    【c# 学习笔记】c#委托是什么
    【c# 学习笔记】面向对象编程的应用
    【c# 学习笔记】接口与抽象类
    【C# 开发技巧】番外篇故事-我是一个线程
    【物联网硬件安全】二、固件分析-固件逆向
    【物联网硬件安全】二、固件分析-固件提取
    【物联网硬件安全】一、硬件分析-电路分析
  • 原文地址:https://www.cnblogs.com/cerana/p/11129640.html
Copyright © 2011-2022 走看看