Ansible的常用模块

Ansible的常用模块

ansible的执行

  • ad-hoc
  • playbook
    ansible ad-hoc
    ad-hoc:临时的命令,执行后结束,不会保存
    使用场景
    比如在多台机器上查看某个进程是否启动,或拷贝指定文件到本地,等等

ad-hoc的命令模式(语法)

在这里插入图片描述

![在这里插入图片描述](https://img-blog.csdnimg.cn/2c0ffb13a1dc402695e5838ce3f1cf40.png)

ac-hoc返回结果的颜色

  • 绿色:被管理端执行成功,并且结果不会发生改变
  • 黄色:被管理端执行成功,但是结果是变化的
  • 红色:执行失败,注意看报错

ansible帮助手册

ansible-doc 模块名

ansible模块:command

 ansible web_group -m command -a '命令(不带特殊符号)'

ansible模块:shell

ansible web_group -m shell -a '命令'

ansible模块:script

## 创建新的仓库配置文件
ansible db01 -m yum_repository -a 'name=local description=xxx baseurl=file:///mnt
gpgcheck=no enabled=yes'
## 创建新的仓库配置,并且文件名和仓库名不同
ansible web01 -m yum_repository -a 'name=local file=zls_local description=xxx
baseurl=file:///mnt gpgcheck=no enabled=yes'
## 追加仓库
ansible lb01 -m yum_repository -a 'name=test2_ansible file=test_ansible
description=xxx baseurl=http://www.baidu.com'
## 删除仓库
ansible lb01 -m yum_repository -a 'name=test2_ansible file=test_ansible state=absent'
yum_repository
- name:仓库名字(如果有file,只是仓库名,如果没有file,文件名和仓库名)
- file:指定仓库的文件名
- description:仓库的描述(name)
- baseurl:仓库的url
- gpgcheck:
- no:不开启 0
- yes:开启 1(默认)
- enabled:
- no:不开启 0
- yes:开启 1 (默认)

ansible文件管理模块:copy

## 远程推送文件
ansible nginx -m copy -a 'src=/etc/passwd dest=/root'
copy
- src:指定源文件的路径
- dest:指定目标路径
- owner:指定属主
- group:指定属组
- mode:指定权限
- backup:
- yes:如果目标路径,存在同名文件,就将目标文件备份
- no:不备份直接覆盖(默认)
- content:将指定文本内容覆盖到目标文件中
- remote_src:将命令变成cp
- yes:将源文件,编程远端的源文件(ansible被管理端)
- no:源文件还是本地文件(ansible管理端 默认)
- follow:拷贝软连接
- yes:会将软连接一起拷贝
- no:会生成一个新的软连接文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值