ansible常用命令

    xiaoxiao2022-11-22  63

    ansible常用命令

    优点: 只需要ssh 无客户端 模块丰富 社区活跃

    语法结构 : ansible [定义的主机名] -m [模块名] -a ‘命令’ 语句中的’'和""无区别

    1.ping 检测主机连通性 ansible all -m ping

    2.command 可以执行任意命令,但不接受管道命令和重定向符号,如果想使用这些,则需要使用Shell模块。 ansible all -m command -a ‘ls’

    3.copy 复制一个文件到远程服务器 ansible all -m copy -a ‘src=本地文件 dest=远程主机目录’

    4.file 用来管理文件夹 ansible all -m file -a ‘path=文件夹 state=动作 mode=权限’ 动作: touch discovery 权限: u+rw,g-wx,o-rwx 或 0755

    5.get_url 从服务器上下载一个文件到远程主机指定的目录 ansible all -m get_url -a ‘url=url地址 dest=远程主机目录 mode: 0440’ 可以进行权限控制,也可以不写

    6.yum ansible all -m yum -a “name=包名 state=状态” 多个包名用逗号隔开 状态: absent 删除 present 安装

    7.service ansible all-m service -a “name=‘服务名’ enabled=‘开机自启’ state=‘动作’” 开机自启 yes或者no 动作: restartd stopped started reloaded

    8.lineinfile模块 ansible all -m lineinfile -a ‘path=文件目录 regrxp=正则匹配的命令 line=匹配的行’

    9.replace模块 ansible all -m replace -a ‘path=文件名 regexp=正则命令 replace=替换的文本’ 指定替换的字符

    10.script模块 ansible all -m script -a ‘脚本名’ 批量执行本地脚本

    11.shell模块 ansible all -m shell -a ‘命令’ 通过/bin/bash执行命令

    12.raw模块 ansible all -m raw -a ‘命令’ raw与shell的区别是没有chdir,creates,removes命令

    13.ansible-doc模块 ansible命令手册 ansible-doc -l 列出所有模块

    最新回复(0)