• ansible常用命令


      ansible 默认提供了很多模块来供我们使用。在 Linux 中,可以通过 ansible-doc -l 命令查看到当前 ansible 都支持哪些模块,通过 ansible-doc  -s  模块名  又可以查看该模块有哪些参数可以使用

    常用模块:
    !所有示例以webserver为匹配目标主机。
    1.ping
    ansible all -m ping
    !检测机器是否可登录,ping模块不需要传送参数
    !注:这里的ping模块并非调用了系统的ping命令,而是类似于登录到远程机器再echo出一个信息。

    2.command
    !可以执行任意命令,但不接受管道命令和重定向符号,如果想使用这些,则需要使用Shell模块。
    ansible all -m command -a "ls" #在所有匹配主机上执行ls命令

    playbook:
    - name: test for command
    command: ls

    3.copy
    #复制一个文件到远程服务器

    ansible all -m copy -a "src=/tmp/text.txt dest=/home/tmp/"
    #将本地text.txt文件复制到所有匹配主机的/home/tmp/路径下。

    playbook:
    - name: test for copy
    copy: src=/tmp/text.txt dest=/home/tmp/ force=yes

    4.file
    这个模块这次构建系统中并没有用到,官方的解释是用来设置文件、文件夹或快链的属性,或者删除文件、快链、文件夹。
    创建一个文件夹,如果目标不存在
    ansible webservers -m file -a "path=/tmp/tdir state=directory mode=0755"
    playbook
    - name: create a directory if it doesn't exist
    - file:
    path: /etc/some_directory
    state: directory
    mode: 0755


    5.get_url
    !从服务器上下载一个文件到远程主机指定的目录
    ansible webservers -m get_url -a "url='http://baidu.com dest=/tmp/ba.html"

    playbook
    - name: download foo.conf
    get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    mode: 0440

    6.yum
    特别适用于批量安装一些依赖包的时候

    ansible webservers -m yum -a "name=httpd state=latest"
    ansible webservers -m yum -a "name=httpd state=absent" !删除包

    playbook
    - name: install the latest version of Apache
    yum:
    name: httpd
    state: latest

    7.service
    控制远程服务器上的服务
    ansible webservers -m service -a "name=nginx state=restart"
    playbook
    - name: restart rmote nginx
    service: name=nginx state=restart

    8.setup
    收集远程服务器信息
    ansible all -m setup
    在playbook中,这项任务默认是执行的,不需要列出。
    ---------------------

    参考:https://blog.csdn.net/kevin3101/article/details/69945516

  • 相关阅读:
    ​《数据库系统概念》5-连接、视图和事务
    ​《数据库系统概念》4-DDL、集合运算、嵌套子查询
    ​《数据库系统概念》3-主键、关系运算
    ​《数据库系统概念》2-存储、事务等的简介
    ​《数据库系统概念》1-数据抽象、模型及SQL
    Web API与JWT认证
    巨杉Tech | 十分钟快速搭建 Wordpress 博客系统
    巨杉内核笔记(一)| SequoiaDB 会话(session)简介
    SequoiaDB巨杉数据库入门:快速搭建流媒体服务器
    微服务?数据库?它们之间到底是啥关系?
  • 原文地址:https://www.cnblogs.com/yuxiaoba/p/9826669.html
Copyright © 2020-2023  润新知